#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200007;
int N, M, R[MAX], D[MAX];
bool T[MAX], C[MAX], isLine;
vector<tuple<int, int, int>> E;
void Clear() {
iota(R, R + MAX, 0);
memset(T, 0, sizeof(T));
memset(D, 0, sizeof(D));
memset(C, 0, sizeof(C));
}
void init(int _N, int _M, vector<int> U, vector<int> V, vector<int> W) {
Clear(); E.clear();
N = _N, M = _M;
for (int i = 0; i < M; ++i) {
E.emplace_back(W[i], U[i], V[i]);
D[U[i]]++;
D[V[i]]++;
}
if (N == M + 1 && *max_element(D, D + MAX) <= 2) isLine = 1;
sort(E.begin(), E.end());
}
int Find(int n) {
T[R[n]] |= T[n];
C[R[n]] |= C[n];
if (n == R[n]) return n;
int r = Find(R[n]);
return R[n] = r;
}
void Union(int a, int b) {
if (++D[a] == 3) T[a] = 1;
if (++D[b] == 3) T[b] = 1;
a = Find(a), b = Find(b);
if (a == b) {
C[a] = 1;
return;
}
R[a] = b;
T[b] |= T[a];
C[b] |= C[a];
}
int getMinimumFuelCapacity(int x, int y) {
if (isLine) return -1;
int l = -1, r = M - 1;
while (l + 1 < r) {
int mid = (l + r) >> 1;
Clear();
for (int i = 0; i <= mid; ++i) {
auto [_, a, b] = E[i];
Union(a, b);
}
bool ok = (Find(x) == Find(y)) && (T[Find(x)] || C[0]);
(ok ? r : l) = mid;
}
auto [ans, a, b] = E[r];
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2252 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2252 KB |
Output is correct |
8 |
Correct |
2 ms |
2392 KB |
Output is correct |
9 |
Correct |
26 ms |
7372 KB |
Output is correct |
10 |
Correct |
31 ms |
8140 KB |
Output is correct |
11 |
Correct |
31 ms |
8256 KB |
Output is correct |
12 |
Correct |
35 ms |
8392 KB |
Output is correct |
13 |
Correct |
33 ms |
8392 KB |
Output is correct |
14 |
Correct |
31 ms |
7880 KB |
Output is correct |
15 |
Correct |
73 ms |
11980 KB |
Output is correct |
16 |
Correct |
78 ms |
11748 KB |
Output is correct |
17 |
Correct |
73 ms |
12088 KB |
Output is correct |
18 |
Correct |
75 ms |
12172 KB |
Output is correct |
19 |
Execution timed out |
2029 ms |
6672 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Execution timed out |
2023 ms |
13096 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2252 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2252 KB |
Output is correct |
8 |
Correct |
2 ms |
2392 KB |
Output is correct |
9 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2392 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
2 ms |
2252 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2252 KB |
Output is correct |
8 |
Correct |
2 ms |
2392 KB |
Output is correct |
9 |
Correct |
26 ms |
7372 KB |
Output is correct |
10 |
Correct |
31 ms |
8140 KB |
Output is correct |
11 |
Correct |
31 ms |
8256 KB |
Output is correct |
12 |
Correct |
35 ms |
8392 KB |
Output is correct |
13 |
Correct |
33 ms |
8392 KB |
Output is correct |
14 |
Correct |
31 ms |
7880 KB |
Output is correct |
15 |
Correct |
73 ms |
11980 KB |
Output is correct |
16 |
Correct |
78 ms |
11748 KB |
Output is correct |
17 |
Correct |
73 ms |
12088 KB |
Output is correct |
18 |
Correct |
75 ms |
12172 KB |
Output is correct |
19 |
Execution timed out |
2023 ms |
13096 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |