#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
class dsu
{
public:
vector<int> p, s, ok; // ok - je tento komponent cyklus alebo obsahuje rozvetvenie?
int root(int x) { return x == p[x] ? x : p[x] = root(p[x]); }
void merge(int a, int b)
{
a = root(a), b = root(b);
if (a == b) return ok[a] = true, void(); // cyklus
if (s[a] < s[b]) swap(a, b);
p[b] = a; s[a] += s[b];
ok[a] |= ok[b];
}
void good(int u) { ok[root(u)] = true; }
dsu(int n): p(vector<int>(n)), s(vector<int>(n, 1)), ok(vector<int>(n, false))
{
for (int i =0;i<n;i++) p[i] = i;
}
};
struct edge { int u, v, w; };
bool cmp(edge a, edge b) { return a.w < b.w; }
int n, m;
vector<edge> e;
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.push_back({U[i], V[i], W[i]});
sort(e.begin(), e.end(), cmp);
}
int getMinimumFuelCapacity(int x, int y) {
dsu c(n);
vector<int> deg(n, 0);
for (int i = 0; i < m; i++)
{
c.merge(e[i].u, e[i].v);
deg[e[i].u]++, deg[e[i].v]++;
if (deg[e[i].u] >= 3) c.good(e[i].u);
if (deg[e[i].v] >= 3) c.good(e[i].v);
if (c.root(x) == c.root(y) && c.ok[c.root(x)]) return e[i].w;
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
49 ms |
5360 KB |
Output is correct |
10 |
Correct |
74 ms |
6136 KB |
Output is correct |
11 |
Correct |
77 ms |
6108 KB |
Output is correct |
12 |
Correct |
82 ms |
6312 KB |
Output is correct |
13 |
Correct |
76 ms |
6392 KB |
Output is correct |
14 |
Execution timed out |
2058 ms |
5824 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
2049 ms |
9984 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
288 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
300 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
352 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
304 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
49 ms |
5360 KB |
Output is correct |
11 |
Correct |
74 ms |
6136 KB |
Output is correct |
12 |
Correct |
77 ms |
6108 KB |
Output is correct |
13 |
Correct |
82 ms |
6312 KB |
Output is correct |
14 |
Correct |
76 ms |
6392 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
300 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
332 KB |
Output is correct |
30 |
Correct |
2 ms |
332 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
352 KB |
Output is correct |
33 |
Correct |
2 ms |
348 KB |
Output is correct |
34 |
Correct |
8 ms |
1132 KB |
Output is correct |
35 |
Correct |
80 ms |
6052 KB |
Output is correct |
36 |
Correct |
80 ms |
6076 KB |
Output is correct |
37 |
Correct |
83 ms |
6056 KB |
Output is correct |
38 |
Correct |
85 ms |
6044 KB |
Output is correct |
39 |
Correct |
81 ms |
6076 KB |
Output is correct |
40 |
Correct |
72 ms |
5676 KB |
Output is correct |
41 |
Correct |
83 ms |
6316 KB |
Output is correct |
42 |
Correct |
79 ms |
6076 KB |
Output is correct |
43 |
Correct |
65 ms |
6120 KB |
Output is correct |
44 |
Correct |
99 ms |
6432 KB |
Output is correct |
45 |
Correct |
102 ms |
10040 KB |
Output is correct |
46 |
Correct |
79 ms |
6120 KB |
Output is correct |
47 |
Correct |
80 ms |
6044 KB |
Output is correct |
48 |
Correct |
89 ms |
6600 KB |
Output is correct |
49 |
Correct |
76 ms |
9924 KB |
Output is correct |
50 |
Correct |
58 ms |
7056 KB |
Output is correct |
51 |
Correct |
82 ms |
7612 KB |
Output is correct |
52 |
Correct |
111 ms |
10600 KB |
Output is correct |
53 |
Correct |
117 ms |
11444 KB |
Output is correct |
54 |
Correct |
130 ms |
12084 KB |
Output is correct |
55 |
Correct |
70 ms |
6040 KB |
Output is correct |
56 |
Correct |
123 ms |
11104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
2 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
304 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
49 ms |
5360 KB |
Output is correct |
10 |
Correct |
74 ms |
6136 KB |
Output is correct |
11 |
Correct |
77 ms |
6108 KB |
Output is correct |
12 |
Correct |
82 ms |
6312 KB |
Output is correct |
13 |
Correct |
76 ms |
6392 KB |
Output is correct |
14 |
Execution timed out |
2058 ms |
5824 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
304 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
49 ms |
5360 KB |
Output is correct |
11 |
Correct |
74 ms |
6136 KB |
Output is correct |
12 |
Correct |
77 ms |
6108 KB |
Output is correct |
13 |
Correct |
82 ms |
6312 KB |
Output is correct |
14 |
Correct |
76 ms |
6392 KB |
Output is correct |
15 |
Execution timed out |
2058 ms |
5824 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |