#include "swap.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int MAX = 200007;
int N, M, Z[MAX], 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));
fill(Z, Z + MAX, 1);
}
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 (Z[a] > Z[b]) swap(a, b);
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;
}
Z[b] += Z[a];
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);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
34652 KB |
Output is correct |
2 |
Correct |
28 ms |
34652 KB |
Output is correct |
3 |
Correct |
29 ms |
34652 KB |
Output is correct |
4 |
Correct |
29 ms |
34652 KB |
Output is correct |
5 |
Correct |
30 ms |
34864 KB |
Output is correct |
6 |
Correct |
29 ms |
34908 KB |
Output is correct |
7 |
Correct |
29 ms |
35152 KB |
Output is correct |
8 |
Correct |
29 ms |
34908 KB |
Output is correct |
9 |
Correct |
75 ms |
38452 KB |
Output is correct |
10 |
Correct |
93 ms |
39508 KB |
Output is correct |
11 |
Correct |
91 ms |
39364 KB |
Output is correct |
12 |
Correct |
91 ms |
39620 KB |
Output is correct |
13 |
Correct |
91 ms |
40592 KB |
Output is correct |
14 |
Correct |
83 ms |
38592 KB |
Output is correct |
15 |
Correct |
129 ms |
41212 KB |
Output is correct |
16 |
Correct |
127 ms |
41240 KB |
Output is correct |
17 |
Correct |
130 ms |
41264 KB |
Output is correct |
18 |
Correct |
126 ms |
42664 KB |
Output is correct |
19 |
Correct |
285 ms |
38928 KB |
Output is correct |
20 |
Correct |
512 ms |
42492 KB |
Output is correct |
21 |
Correct |
511 ms |
42624 KB |
Output is correct |
22 |
Correct |
554 ms |
42796 KB |
Output is correct |
23 |
Execution timed out |
2065 ms |
43040 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
34652 KB |
Output is correct |
2 |
Correct |
28 ms |
34652 KB |
Output is correct |
3 |
Execution timed out |
2031 ms |
41412 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
34652 KB |
Output is correct |
2 |
Correct |
28 ms |
34652 KB |
Output is correct |
3 |
Correct |
29 ms |
34652 KB |
Output is correct |
4 |
Correct |
29 ms |
34652 KB |
Output is correct |
5 |
Correct |
30 ms |
34864 KB |
Output is correct |
6 |
Correct |
29 ms |
34908 KB |
Output is correct |
7 |
Correct |
29 ms |
35152 KB |
Output is correct |
8 |
Correct |
29 ms |
34908 KB |
Output is correct |
9 |
Correct |
28 ms |
34816 KB |
Output is correct |
10 |
Correct |
29 ms |
34908 KB |
Output is correct |
11 |
Correct |
29 ms |
34856 KB |
Output is correct |
12 |
Correct |
30 ms |
34900 KB |
Output is correct |
13 |
Correct |
29 ms |
34896 KB |
Output is correct |
14 |
Correct |
29 ms |
34896 KB |
Output is correct |
15 |
Correct |
29 ms |
34904 KB |
Output is correct |
16 |
Correct |
29 ms |
34904 KB |
Output is correct |
17 |
Correct |
29 ms |
34908 KB |
Output is correct |
18 |
Correct |
31 ms |
34904 KB |
Output is correct |
19 |
Correct |
29 ms |
34908 KB |
Output is correct |
20 |
Correct |
29 ms |
34900 KB |
Output is correct |
21 |
Correct |
29 ms |
34904 KB |
Output is correct |
22 |
Correct |
34 ms |
34944 KB |
Output is correct |
23 |
Correct |
30 ms |
34984 KB |
Output is correct |
24 |
Correct |
30 ms |
34908 KB |
Output is correct |
25 |
Correct |
36 ms |
34884 KB |
Output is correct |
26 |
Correct |
30 ms |
34864 KB |
Output is correct |
27 |
Correct |
29 ms |
34888 KB |
Output is correct |
28 |
Correct |
30 ms |
34908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
34816 KB |
Output is correct |
2 |
Correct |
29 ms |
34652 KB |
Output is correct |
3 |
Correct |
28 ms |
34652 KB |
Output is correct |
4 |
Correct |
29 ms |
34652 KB |
Output is correct |
5 |
Correct |
29 ms |
34652 KB |
Output is correct |
6 |
Correct |
30 ms |
34864 KB |
Output is correct |
7 |
Correct |
29 ms |
34908 KB |
Output is correct |
8 |
Correct |
29 ms |
35152 KB |
Output is correct |
9 |
Correct |
29 ms |
34908 KB |
Output is correct |
10 |
Correct |
75 ms |
38452 KB |
Output is correct |
11 |
Correct |
93 ms |
39508 KB |
Output is correct |
12 |
Correct |
91 ms |
39364 KB |
Output is correct |
13 |
Correct |
91 ms |
39620 KB |
Output is correct |
14 |
Correct |
91 ms |
40592 KB |
Output is correct |
15 |
Correct |
29 ms |
34908 KB |
Output is correct |
16 |
Correct |
29 ms |
34856 KB |
Output is correct |
17 |
Correct |
30 ms |
34900 KB |
Output is correct |
18 |
Correct |
29 ms |
34896 KB |
Output is correct |
19 |
Correct |
29 ms |
34896 KB |
Output is correct |
20 |
Correct |
29 ms |
34904 KB |
Output is correct |
21 |
Correct |
29 ms |
34904 KB |
Output is correct |
22 |
Correct |
29 ms |
34908 KB |
Output is correct |
23 |
Correct |
31 ms |
34904 KB |
Output is correct |
24 |
Correct |
29 ms |
34908 KB |
Output is correct |
25 |
Correct |
29 ms |
34900 KB |
Output is correct |
26 |
Correct |
29 ms |
34904 KB |
Output is correct |
27 |
Correct |
34 ms |
34944 KB |
Output is correct |
28 |
Correct |
30 ms |
34984 KB |
Output is correct |
29 |
Correct |
30 ms |
34908 KB |
Output is correct |
30 |
Correct |
36 ms |
34884 KB |
Output is correct |
31 |
Correct |
30 ms |
34864 KB |
Output is correct |
32 |
Correct |
29 ms |
34888 KB |
Output is correct |
33 |
Correct |
30 ms |
34908 KB |
Output is correct |
34 |
Correct |
40 ms |
35612 KB |
Output is correct |
35 |
Correct |
115 ms |
39624 KB |
Output is correct |
36 |
Correct |
97 ms |
39624 KB |
Output is correct |
37 |
Correct |
90 ms |
39588 KB |
Output is correct |
38 |
Correct |
96 ms |
39620 KB |
Output is correct |
39 |
Correct |
91 ms |
39744 KB |
Output is correct |
40 |
Correct |
94 ms |
39668 KB |
Output is correct |
41 |
Correct |
93 ms |
39624 KB |
Output is correct |
42 |
Correct |
94 ms |
39620 KB |
Output is correct |
43 |
Correct |
106 ms |
38348 KB |
Output is correct |
44 |
Correct |
104 ms |
40508 KB |
Output is correct |
45 |
Correct |
151 ms |
49332 KB |
Output is correct |
46 |
Correct |
93 ms |
39572 KB |
Output is correct |
47 |
Correct |
95 ms |
40136 KB |
Output is correct |
48 |
Correct |
110 ms |
43716 KB |
Output is correct |
49 |
Correct |
98 ms |
40840 KB |
Output is correct |
50 |
Correct |
83 ms |
40392 KB |
Output is correct |
51 |
Correct |
155 ms |
46328 KB |
Output is correct |
52 |
Correct |
146 ms |
44732 KB |
Output is correct |
53 |
Correct |
219 ms |
47312 KB |
Output is correct |
54 |
Correct |
183 ms |
46440 KB |
Output is correct |
55 |
Correct |
128 ms |
38348 KB |
Output is correct |
56 |
Correct |
193 ms |
50368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
34652 KB |
Output is correct |
2 |
Correct |
28 ms |
34652 KB |
Output is correct |
3 |
Correct |
29 ms |
34652 KB |
Output is correct |
4 |
Correct |
29 ms |
34652 KB |
Output is correct |
5 |
Correct |
30 ms |
34864 KB |
Output is correct |
6 |
Correct |
29 ms |
34908 KB |
Output is correct |
7 |
Correct |
29 ms |
35152 KB |
Output is correct |
8 |
Correct |
29 ms |
34908 KB |
Output is correct |
9 |
Correct |
75 ms |
38452 KB |
Output is correct |
10 |
Correct |
93 ms |
39508 KB |
Output is correct |
11 |
Correct |
91 ms |
39364 KB |
Output is correct |
12 |
Correct |
91 ms |
39620 KB |
Output is correct |
13 |
Correct |
91 ms |
40592 KB |
Output is correct |
14 |
Correct |
83 ms |
38592 KB |
Output is correct |
15 |
Correct |
129 ms |
41212 KB |
Output is correct |
16 |
Correct |
127 ms |
41240 KB |
Output is correct |
17 |
Correct |
130 ms |
41264 KB |
Output is correct |
18 |
Correct |
126 ms |
42664 KB |
Output is correct |
19 |
Execution timed out |
2031 ms |
41412 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
34816 KB |
Output is correct |
2 |
Correct |
29 ms |
34652 KB |
Output is correct |
3 |
Correct |
28 ms |
34652 KB |
Output is correct |
4 |
Correct |
29 ms |
34652 KB |
Output is correct |
5 |
Correct |
29 ms |
34652 KB |
Output is correct |
6 |
Correct |
30 ms |
34864 KB |
Output is correct |
7 |
Correct |
29 ms |
34908 KB |
Output is correct |
8 |
Correct |
29 ms |
35152 KB |
Output is correct |
9 |
Correct |
29 ms |
34908 KB |
Output is correct |
10 |
Correct |
75 ms |
38452 KB |
Output is correct |
11 |
Correct |
93 ms |
39508 KB |
Output is correct |
12 |
Correct |
91 ms |
39364 KB |
Output is correct |
13 |
Correct |
91 ms |
39620 KB |
Output is correct |
14 |
Correct |
91 ms |
40592 KB |
Output is correct |
15 |
Correct |
83 ms |
38592 KB |
Output is correct |
16 |
Correct |
129 ms |
41212 KB |
Output is correct |
17 |
Correct |
127 ms |
41240 KB |
Output is correct |
18 |
Correct |
130 ms |
41264 KB |
Output is correct |
19 |
Correct |
126 ms |
42664 KB |
Output is correct |
20 |
Execution timed out |
2031 ms |
41412 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |