#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 u0, int v0) {
int u = leader(u0);
int v = leader(v0);
if (u == v) {
ok[u] = true;
return false;
}
if (siz[u] > siz[v]) swap(u, v);
siz[v] += siz[u];
if (++deg[u0] >= 3 || ++deg[v0] >= 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 |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
30 ms |
4804 KB |
Output is correct |
10 |
Correct |
38 ms |
5760 KB |
Output is correct |
11 |
Correct |
40 ms |
5756 KB |
Output is correct |
12 |
Correct |
42 ms |
6052 KB |
Output is correct |
13 |
Correct |
39 ms |
6096 KB |
Output is correct |
14 |
Execution timed out |
2033 ms |
5572 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Execution timed out |
2033 ms |
10048 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
452 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
30 ms |
4804 KB |
Output is correct |
11 |
Correct |
38 ms |
5760 KB |
Output is correct |
12 |
Correct |
40 ms |
5756 KB |
Output is correct |
13 |
Correct |
42 ms |
6052 KB |
Output is correct |
14 |
Correct |
39 ms |
6096 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
452 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
5 ms |
1116 KB |
Output is correct |
35 |
Correct |
41 ms |
5924 KB |
Output is correct |
36 |
Correct |
56 ms |
5732 KB |
Output is correct |
37 |
Correct |
41 ms |
5748 KB |
Output is correct |
38 |
Correct |
43 ms |
5736 KB |
Output is correct |
39 |
Correct |
41 ms |
5672 KB |
Output is correct |
40 |
Correct |
38 ms |
5220 KB |
Output is correct |
41 |
Correct |
47 ms |
6064 KB |
Output is correct |
42 |
Correct |
43 ms |
5768 KB |
Output is correct |
43 |
Correct |
35 ms |
5780 KB |
Output is correct |
44 |
Correct |
54 ms |
6048 KB |
Output is correct |
45 |
Correct |
54 ms |
8708 KB |
Output is correct |
46 |
Correct |
46 ms |
5740 KB |
Output is correct |
47 |
Correct |
41 ms |
6000 KB |
Output is correct |
48 |
Correct |
43 ms |
6336 KB |
Output is correct |
49 |
Correct |
46 ms |
8560 KB |
Output is correct |
50 |
Correct |
44 ms |
6992 KB |
Output is correct |
51 |
Correct |
52 ms |
7424 KB |
Output is correct |
52 |
Correct |
75 ms |
9728 KB |
Output is correct |
53 |
Correct |
63 ms |
10320 KB |
Output is correct |
54 |
Correct |
77 ms |
11340 KB |
Output is correct |
55 |
Correct |
38 ms |
5816 KB |
Output is correct |
56 |
Correct |
80 ms |
9912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
30 ms |
4804 KB |
Output is correct |
10 |
Correct |
38 ms |
5760 KB |
Output is correct |
11 |
Correct |
40 ms |
5756 KB |
Output is correct |
12 |
Correct |
42 ms |
6052 KB |
Output is correct |
13 |
Correct |
39 ms |
6096 KB |
Output is correct |
14 |
Execution timed out |
2033 ms |
5572 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
444 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
30 ms |
4804 KB |
Output is correct |
11 |
Correct |
38 ms |
5760 KB |
Output is correct |
12 |
Correct |
40 ms |
5756 KB |
Output is correct |
13 |
Correct |
42 ms |
6052 KB |
Output is correct |
14 |
Correct |
39 ms |
6096 KB |
Output is correct |
15 |
Execution timed out |
2033 ms |
5572 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |