#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200007;
int N, M, R[MAX], D[MAX];
bool T[MAX], isLine;
tuple<int, int, int> E[MAX];
void init(int _N, int _M, vector<int> U, vector<int> V, vector<int> W) {
N = _N, M = _M;
for (int i = 1; i <= M; ++i) {
E[i] = {U[i], V[i], W[i]};
D[U[i]]++;
D[V[i]]++;
}
if (_N == _M + 1 && *max_element(D, D + MAX) == 2) isLine = 1;
sort(E + 1, E + M + 1);
}
void Clear() {
iota(R, R + MAX, 0);
memset(T, 0, sizeof(T));
memset(D, 0, sizeof(D));
}
int Find(int n) {
if (n == R[n]) return n;
int r = Find(R[n]);
T[r] |= T[R[n]];
return R[n] = r;
}
void Union(int a, int b) {
if (++D[a] == 3) T[a] = 1;
if (++D[b] == 3) T[b] = 1;
a = Find(a), b = Find(b);
if (a == b) return;
R[a] = b;
T[b] |= T[a];
}
int getMinimumFuelCapacity(int x, int y) {
if (isLine) return -1;
int l = 1, r = M + 1;
while (l + 1 < r) {
int mid = (l + r) >> 1;
Clear();
for (int i = 1; i <= mid; ++i) {
auto [_, a, b] =E[i];
Union(a, b);
}
bool ok = (Find(x) == Find(y)) && T[Find(x)];
(ok ? R : L) = mid;
}
auto [ans, _, _] = E[L];
return ans;
}
Compilation message
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:57:13: error: 'L' was not declared in this scope
57 | (ok ? R : L) = mid;
| ^
swap.cpp:60:16: error: redeclaration of 'auto _'
60 | auto [ans, _, _] = E[L];
| ^
swap.cpp:60:13: note: 'auto _' previously declared here
60 | auto [ans, _, _] = E[L];
| ^
swap.cpp:60:23: error: 'L' was not declared in this scope
60 | auto [ans, _, _] = E[L];
| ^
swap.cpp:61:9: error: use of 'ans' before deduction of 'auto'
61 | return ans;
| ^~~
swap.cpp:60:7: warning: unused structured binding declaration [-Wunused-variable]
60 | auto [ans, _, _] = E[L];
| ^~~~~~~~~~~
swap.cpp:60:13: warning: unused variable '_' [-Wunused-variable]
60 | auto [ans, _, _] = E[L];
| ^