#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
int N;
vector<tuple<int, int, int>> edges;
constexpr int inf = 2e9;
void init(int n, int M, vector<int> U, vector<int> V, vector<int> W) {
N = n;
for (int i = 0; i < M; i++) {
edges.emplace_back(W[i], U[i], V[i]);
}
sort(edges.begin(), edges.end());
}
int getMinimumFuelCapacity(int X, int Y) {
vector<int> p(N);
iota(p.begin(), p.end(), 0);
function<int(int)> find = [&](int x) {
return x == p[x] ? x : p[x] = find(p[x]);
};
vector<int> sz(N, 1), cnt(N);
auto unite = [&](int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
cnt[x]++;
return;
}
if (sz[x] > sz[y]) {
swap(x, y);
}
p[x] = y;
sz[y] += sz[x];
cnt[y] += cnt[x] + 1;
};
for (auto [z, x, y] : edges) {
unite(x, y);
if (find(X) == find(Y)) {
if (cnt[find(X)] >= sz[find(X)]) {
return z;
}
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
34 ms |
3964 KB |
Output is correct |
10 |
Correct |
51 ms |
4376 KB |
Output is correct |
11 |
Correct |
58 ms |
4380 KB |
Output is correct |
12 |
Correct |
55 ms |
4540 KB |
Output is correct |
13 |
Correct |
51 ms |
4472 KB |
Output is correct |
14 |
Execution timed out |
2057 ms |
4212 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
2080 ms |
5864 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
34 ms |
3964 KB |
Output is correct |
11 |
Correct |
51 ms |
4376 KB |
Output is correct |
12 |
Correct |
58 ms |
4380 KB |
Output is correct |
13 |
Correct |
55 ms |
4540 KB |
Output is correct |
14 |
Correct |
51 ms |
4472 KB |
Output is correct |
15 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
34 ms |
3964 KB |
Output is correct |
10 |
Correct |
51 ms |
4376 KB |
Output is correct |
11 |
Correct |
58 ms |
4380 KB |
Output is correct |
12 |
Correct |
55 ms |
4540 KB |
Output is correct |
13 |
Correct |
51 ms |
4472 KB |
Output is correct |
14 |
Execution timed out |
2057 ms |
4212 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
34 ms |
3964 KB |
Output is correct |
11 |
Correct |
51 ms |
4376 KB |
Output is correct |
12 |
Correct |
58 ms |
4380 KB |
Output is correct |
13 |
Correct |
55 ms |
4540 KB |
Output is correct |
14 |
Correct |
51 ms |
4472 KB |
Output is correct |
15 |
Execution timed out |
2057 ms |
4212 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |