#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<array<int, 3>> edges;
struct DSU {
vector<int> f;
vector<int> siz;
vector<int> deg;
vector<bool> ok;
DSU(int n) : f(n), siz(n, 1), deg(n, 0), ok(n, false) { iota(f.begin(), f.end(), 0); }
int leader(int u) {
while (u != f[u]) u = f[u] = f[f[u]];
return u;
}
bool unionize(int u, int v) {
u = leader(u);
v = leader(v);
if (u == v) {
ok[u] = true;
return false;
}
if (siz[u] > siz[v]) swap(u, v);
siz[v] += siz[u];
deg[u]++;
deg[v]++;
if (deg[u] >= 3 || deg[v] >= 3) ok[v] = true;
ok[v] = ok[v] | ok[u];
f[u] = v;
return true;
}
bool same(int u, int v) {
return leader(u) == leader(v);
}
bool isOk(int u) {
return ok[leader(u)];
}
};
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n = N;
m = M;
edges.resize(m);
for (int i = 0; i < m; i++) {
edges[i] = {U[i], V[i], W[i]};
}
sort(edges.begin(), edges.end(), [&](array<int, 3> e0, array<int, 3> e1) { return e0[2] < e1[2]; });
}
int getMinimumFuelCapacity(int X, int Y) {
DSU dsu(n);
for (auto [u, v, w] : edges) {
dsu.unionize(u, v);
if (dsu.same(X, Y) && dsu.isOk(X)) return w;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
440 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Execution timed out |
2041 ms |
9836 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
440 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
440 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
440 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Incorrect |
1 ms |
440 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |