#include "swap.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int MAX = 200007;
int N, M, D[MAX];
bool isLine;
vector<tuple<int, int, int>> E;
vector<pii> R[MAX], T[MAX], C[MAX];
void Clear() {
for (int i = 0; i < MAX; ++i) {
R[i].clear();
T[i].clear();
C[i].clear();
R[i].emplace_back(-1, i);
T[i].emplace_back(-1, 0);
C[i].emplace_back(-1, 0);
}
memset(D, 0, sizeof(D));
}
int Find(int n, int t) {
int tr = R[n].back().second;
if (T[n].back().second && !T[tr].back().second) T[tr].emplace_back(t, 1);
if (C[n].back().second && !C[tr].back().second) C[tr].emplace_back(t, 1);
if (n == tr) return n;
int r = Find(tr, t);
if (R[n].back().second != r) R[n].emplace_back(t, r);
return R[n].back().second;
}
void Union(int a, int b, int t) {
if (++D[a] == 3 && !T[a].back().second) T[a].emplace_back(t, 1);
if (++D[b] == 3 && !T[b].back().second) T[b].emplace_back(t, 1);
a = Find(a, t), b = Find(b, t);
if (a == b) {
if (!C[a].back().second) C[a].emplace_back(t, 1);
return;
}
R[a].emplace_back(t, b);
if (T[a].back().second && !T[b].back().second) T[b].emplace_back(t, 1);
if (C[a].back().second && !C[b].back().second) C[b].emplace_back(t, 1);
}
int TFind(vector<pii>& S, int t) {
auto it = upper_bound(S.begin(), S.end(), pii{t, 1 << 30});
return (*--it).second;
}
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;
int rx = x, ry = y;
while (1) {
int t = TFind(R[rx], mid);
if (rx == t) break;
rx = t;
}
while (1) {
int t = TFind(R[ry], mid);
if (ry == t) break;
ry = t;
}
bool ok = (rx == ry && (TFind(T[rx], mid) || TFind(C[rx], mid)));
(ok ? r : l) = mid;
}
auto [ans, a, b] = E[r];
return ans;
}
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.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());
Clear();
for (int i = 0; i < M; ++i) {
auto [_, a, b] = E[i];
Union(a, b, i);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
33880 KB |
Output is correct |
2 |
Correct |
31 ms |
34036 KB |
Output is correct |
3 |
Correct |
31 ms |
33884 KB |
Output is correct |
4 |
Correct |
30 ms |
33984 KB |
Output is correct |
5 |
Correct |
28 ms |
33932 KB |
Output is correct |
6 |
Correct |
28 ms |
33876 KB |
Output is correct |
7 |
Correct |
35 ms |
34140 KB |
Output is correct |
8 |
Correct |
33 ms |
34148 KB |
Output is correct |
9 |
Correct |
77 ms |
37828 KB |
Output is correct |
10 |
Correct |
88 ms |
38756 KB |
Output is correct |
11 |
Correct |
94 ms |
38776 KB |
Output is correct |
12 |
Correct |
103 ms |
39052 KB |
Output is correct |
13 |
Correct |
100 ms |
40692 KB |
Output is correct |
14 |
Correct |
87 ms |
38032 KB |
Output is correct |
15 |
Correct |
135 ms |
40656 KB |
Output is correct |
16 |
Correct |
154 ms |
40376 KB |
Output is correct |
17 |
Correct |
133 ms |
40752 KB |
Output is correct |
18 |
Correct |
136 ms |
42420 KB |
Output is correct |
19 |
Correct |
295 ms |
38348 KB |
Output is correct |
20 |
Correct |
522 ms |
41792 KB |
Output is correct |
21 |
Correct |
510 ms |
41940 KB |
Output is correct |
22 |
Correct |
614 ms |
42052 KB |
Output is correct |
23 |
Execution timed out |
2031 ms |
43488 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
33880 KB |
Output is correct |
2 |
Correct |
31 ms |
34036 KB |
Output is correct |
3 |
Execution timed out |
2017 ms |
40648 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
33880 KB |
Output is correct |
2 |
Correct |
31 ms |
34036 KB |
Output is correct |
3 |
Correct |
31 ms |
33884 KB |
Output is correct |
4 |
Correct |
30 ms |
33984 KB |
Output is correct |
5 |
Correct |
28 ms |
33932 KB |
Output is correct |
6 |
Correct |
28 ms |
33876 KB |
Output is correct |
7 |
Correct |
35 ms |
34140 KB |
Output is correct |
8 |
Correct |
33 ms |
34148 KB |
Output is correct |
9 |
Correct |
28 ms |
33884 KB |
Output is correct |
10 |
Correct |
28 ms |
34004 KB |
Output is correct |
11 |
Correct |
28 ms |
34028 KB |
Output is correct |
12 |
Correct |
35 ms |
34136 KB |
Output is correct |
13 |
Correct |
29 ms |
34396 KB |
Output is correct |
14 |
Correct |
29 ms |
34096 KB |
Output is correct |
15 |
Correct |
27 ms |
34136 KB |
Output is correct |
16 |
Correct |
29 ms |
34140 KB |
Output is correct |
17 |
Correct |
28 ms |
33876 KB |
Output is correct |
18 |
Correct |
29 ms |
34140 KB |
Output is correct |
19 |
Correct |
36 ms |
34128 KB |
Output is correct |
20 |
Correct |
29 ms |
34140 KB |
Output is correct |
21 |
Correct |
28 ms |
34044 KB |
Output is correct |
22 |
Correct |
31 ms |
34140 KB |
Output is correct |
23 |
Correct |
28 ms |
34140 KB |
Output is correct |
24 |
Correct |
39 ms |
34140 KB |
Output is correct |
25 |
Correct |
28 ms |
34008 KB |
Output is correct |
26 |
Correct |
32 ms |
34184 KB |
Output is correct |
27 |
Correct |
36 ms |
33936 KB |
Output is correct |
28 |
Correct |
28 ms |
34136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
33884 KB |
Output is correct |
2 |
Correct |
29 ms |
33880 KB |
Output is correct |
3 |
Correct |
31 ms |
34036 KB |
Output is correct |
4 |
Correct |
31 ms |
33884 KB |
Output is correct |
5 |
Correct |
30 ms |
33984 KB |
Output is correct |
6 |
Correct |
28 ms |
33932 KB |
Output is correct |
7 |
Correct |
28 ms |
33876 KB |
Output is correct |
8 |
Correct |
35 ms |
34140 KB |
Output is correct |
9 |
Correct |
33 ms |
34148 KB |
Output is correct |
10 |
Correct |
77 ms |
37828 KB |
Output is correct |
11 |
Correct |
88 ms |
38756 KB |
Output is correct |
12 |
Correct |
94 ms |
38776 KB |
Output is correct |
13 |
Correct |
103 ms |
39052 KB |
Output is correct |
14 |
Correct |
100 ms |
40692 KB |
Output is correct |
15 |
Correct |
28 ms |
34004 KB |
Output is correct |
16 |
Correct |
28 ms |
34028 KB |
Output is correct |
17 |
Correct |
35 ms |
34136 KB |
Output is correct |
18 |
Correct |
29 ms |
34396 KB |
Output is correct |
19 |
Correct |
29 ms |
34096 KB |
Output is correct |
20 |
Correct |
27 ms |
34136 KB |
Output is correct |
21 |
Correct |
29 ms |
34140 KB |
Output is correct |
22 |
Correct |
28 ms |
33876 KB |
Output is correct |
23 |
Correct |
29 ms |
34140 KB |
Output is correct |
24 |
Correct |
36 ms |
34128 KB |
Output is correct |
25 |
Correct |
29 ms |
34140 KB |
Output is correct |
26 |
Correct |
28 ms |
34044 KB |
Output is correct |
27 |
Correct |
31 ms |
34140 KB |
Output is correct |
28 |
Correct |
28 ms |
34140 KB |
Output is correct |
29 |
Correct |
39 ms |
34140 KB |
Output is correct |
30 |
Correct |
28 ms |
34008 KB |
Output is correct |
31 |
Correct |
32 ms |
34184 KB |
Output is correct |
32 |
Correct |
36 ms |
33936 KB |
Output is correct |
33 |
Correct |
28 ms |
34136 KB |
Output is correct |
34 |
Correct |
47 ms |
34832 KB |
Output is correct |
35 |
Correct |
100 ms |
38896 KB |
Output is correct |
36 |
Correct |
106 ms |
39044 KB |
Output is correct |
37 |
Correct |
89 ms |
38968 KB |
Output is correct |
38 |
Correct |
105 ms |
39032 KB |
Output is correct |
39 |
Correct |
90 ms |
39108 KB |
Output is correct |
40 |
Correct |
96 ms |
39108 KB |
Output is correct |
41 |
Correct |
104 ms |
39072 KB |
Output is correct |
42 |
Correct |
92 ms |
39044 KB |
Output is correct |
43 |
Correct |
116 ms |
37572 KB |
Output is correct |
44 |
Correct |
95 ms |
39792 KB |
Output is correct |
45 |
Correct |
176 ms |
47992 KB |
Output is correct |
46 |
Correct |
110 ms |
40904 KB |
Output is correct |
47 |
Correct |
106 ms |
41340 KB |
Output is correct |
48 |
Correct |
118 ms |
45508 KB |
Output is correct |
49 |
Correct |
83 ms |
42428 KB |
Output is correct |
50 |
Correct |
83 ms |
41924 KB |
Output is correct |
51 |
Correct |
144 ms |
48708 KB |
Output is correct |
52 |
Correct |
158 ms |
47408 KB |
Output is correct |
53 |
Correct |
173 ms |
51076 KB |
Output is correct |
54 |
Correct |
217 ms |
49528 KB |
Output is correct |
55 |
Correct |
143 ms |
39368 KB |
Output is correct |
56 |
Correct |
237 ms |
54472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
33880 KB |
Output is correct |
2 |
Correct |
31 ms |
34036 KB |
Output is correct |
3 |
Correct |
31 ms |
33884 KB |
Output is correct |
4 |
Correct |
30 ms |
33984 KB |
Output is correct |
5 |
Correct |
28 ms |
33932 KB |
Output is correct |
6 |
Correct |
28 ms |
33876 KB |
Output is correct |
7 |
Correct |
35 ms |
34140 KB |
Output is correct |
8 |
Correct |
33 ms |
34148 KB |
Output is correct |
9 |
Correct |
77 ms |
37828 KB |
Output is correct |
10 |
Correct |
88 ms |
38756 KB |
Output is correct |
11 |
Correct |
94 ms |
38776 KB |
Output is correct |
12 |
Correct |
103 ms |
39052 KB |
Output is correct |
13 |
Correct |
100 ms |
40692 KB |
Output is correct |
14 |
Correct |
87 ms |
38032 KB |
Output is correct |
15 |
Correct |
135 ms |
40656 KB |
Output is correct |
16 |
Correct |
154 ms |
40376 KB |
Output is correct |
17 |
Correct |
133 ms |
40752 KB |
Output is correct |
18 |
Correct |
136 ms |
42420 KB |
Output is correct |
19 |
Execution timed out |
2017 ms |
40648 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
33884 KB |
Output is correct |
2 |
Correct |
29 ms |
33880 KB |
Output is correct |
3 |
Correct |
31 ms |
34036 KB |
Output is correct |
4 |
Correct |
31 ms |
33884 KB |
Output is correct |
5 |
Correct |
30 ms |
33984 KB |
Output is correct |
6 |
Correct |
28 ms |
33932 KB |
Output is correct |
7 |
Correct |
28 ms |
33876 KB |
Output is correct |
8 |
Correct |
35 ms |
34140 KB |
Output is correct |
9 |
Correct |
33 ms |
34148 KB |
Output is correct |
10 |
Correct |
77 ms |
37828 KB |
Output is correct |
11 |
Correct |
88 ms |
38756 KB |
Output is correct |
12 |
Correct |
94 ms |
38776 KB |
Output is correct |
13 |
Correct |
103 ms |
39052 KB |
Output is correct |
14 |
Correct |
100 ms |
40692 KB |
Output is correct |
15 |
Correct |
87 ms |
38032 KB |
Output is correct |
16 |
Correct |
135 ms |
40656 KB |
Output is correct |
17 |
Correct |
154 ms |
40376 KB |
Output is correct |
18 |
Correct |
133 ms |
40752 KB |
Output is correct |
19 |
Correct |
136 ms |
42420 KB |
Output is correct |
20 |
Execution timed out |
2017 ms |
40648 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |