#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]);
T[r] |= T[n];
C[r] |= C[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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2312 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2228 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
25 ms |
6864 KB |
Output is correct |
10 |
Correct |
35 ms |
7624 KB |
Output is correct |
11 |
Correct |
30 ms |
7376 KB |
Output is correct |
12 |
Correct |
36 ms |
7632 KB |
Output is correct |
13 |
Correct |
31 ms |
7624 KB |
Output is correct |
14 |
Correct |
29 ms |
7116 KB |
Output is correct |
15 |
Correct |
75 ms |
10400 KB |
Output is correct |
16 |
Correct |
75 ms |
10180 KB |
Output is correct |
17 |
Correct |
74 ms |
10184 KB |
Output is correct |
18 |
Correct |
72 ms |
10184 KB |
Output is correct |
19 |
Execution timed out |
2029 ms |
6200 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Execution timed out |
2073 ms |
13000 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2312 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2228 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
2 ms |
2312 KB |
Output is correct |
6 |
Correct |
2 ms |
2396 KB |
Output is correct |
7 |
Correct |
2 ms |
2228 KB |
Output is correct |
8 |
Correct |
2 ms |
2396 KB |
Output is correct |
9 |
Correct |
25 ms |
6864 KB |
Output is correct |
10 |
Correct |
35 ms |
7624 KB |
Output is correct |
11 |
Correct |
30 ms |
7376 KB |
Output is correct |
12 |
Correct |
36 ms |
7632 KB |
Output is correct |
13 |
Correct |
31 ms |
7624 KB |
Output is correct |
14 |
Correct |
29 ms |
7116 KB |
Output is correct |
15 |
Correct |
75 ms |
10400 KB |
Output is correct |
16 |
Correct |
75 ms |
10180 KB |
Output is correct |
17 |
Correct |
74 ms |
10184 KB |
Output is correct |
18 |
Correct |
72 ms |
10184 KB |
Output is correct |
19 |
Execution timed out |
2073 ms |
13000 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |