#include <bits/stdc++.h>
#include "swap.h"
using namespace std;
vector<int> ds, ww1, ww2;
int find(int i) { return ds[i] < 0 ? i : find(ds[i]);}
void join(int i, int j, int w, int bridge) {
i = find(i);
j = find(j);
if (i == j) ww2[i] = min(ww2[i], w);
else {
if (ds[i] > ds[j]) swap(i, j);
ds[i] += ds[j], ds[j] = i;
ww1[j] = w;
ww2[i] = min(ww2[i], max(w, bridge ? 0 : ww2[j]));
}
}
void init(int n, int m, std::vector<int> ii, std::vector<int> jj, std::vector<int> ww) {
vector<int> hh(m), dd(n);
for (int i = 0; i < m; i++) hh[i] = i;
sort(hh.begin(), hh.end(), [&](int i, int j) {return ww[i] < ww[j];});
ds.assign(n, -1);
ww1.assign(n, INF);
ww2.assign(n, INF);
for (int h : hh) {
dd[ii[h]]++, dd[jj[h]]++;
join(ii[h], jj[h], ww[h], dd[ii[h]] >= 3 || dd[jj[h]] >= 3);
}
}
int getMinimumFuelCapacity(int i, int j) {
int w = -1;
while (i != j) {
if (ww1[i] < ww1[j]) {
w = ww1[i];
i = ds[i];
} else {
w = ww1[j];
j = ds[j];
}
}
while (i >= 0) {
if (ww2[i] != INF) return max(w, ww2[i]);
w = ww1[i];
i = ds[i];
}
return -1;
}
Compilation message
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:26:16: error: 'INF' was not declared in this scope
26 | ww1.assign(n, INF);
| ^~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:46:17: error: 'INF' was not declared in this scope
46 | if (ww2[i] != INF) return max(w, ww2[i]);
| ^~~