#include <bits/stdc++.h>
#ifdef MINA
#include "grader.cpp"
#endif
using namespace std;
#define ll long long
const int N = 200'005;
int n, m;
array<int, 3> e[N];
void init(int _n, int _m, vector<int> u, vector<int> v, vector<int> w) {
n = _n, m = _m;
for (int i = 0; i < m; i++) {
e[i] = {u[i], v[i], w[i]};
}
sort(e, e + m, [&] (array<int, 3> x, array<int, 3> y) {return x[2] < y[2];});
}
int par[N], sz[N], deg[N], mx[N], cnt[N];
int find(int u) {
if (par[u] == u) {
return u;
}
return par[u] = find(par[u]);
}
void join(int u, int v) {
int du = ++deg[u], dv = ++deg[v];
u = find(u), v = find(v);
mx[u] = max(mx[u], du);
mx[v] = max(mx[v], dv);
cnt[u]++;
if (u == v) return;
if (sz[u] < sz[v]) swap(u, v);
par[v] = u;
sz[u] += sz[v];
cnt[u] += cnt[v];
mx[u] = max(mx[u], mx[v]);
}
int getMinimumFuelCapacity(int x, int y) {
int l = 0, r = m - 1;
while (l <= r) {
int md = ((l + r) >> 1);
for (int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
deg[i] = 0;
mx[i] = 0;
cnt[i] = 0;
}
for (int j = 0; j <= md; j++) {
join(e[j][0], e[j][1]);
}
if (find(x) == find(y) && (mx[find(x)] > 2 || cnt[find(x)] >= sz[x])) {
r = md - 1;
} else {
l = md + 1;
}
}
if (l == m) {
return -1;
}
return e[l][2];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4440 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |