#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;
return Find(tr, t);
}
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 |
28 ms |
34768 KB |
Output is correct |
2 |
Correct |
31 ms |
34640 KB |
Output is correct |
3 |
Correct |
29 ms |
34652 KB |
Output is correct |
4 |
Correct |
29 ms |
34648 KB |
Output is correct |
5 |
Correct |
29 ms |
34896 KB |
Output is correct |
6 |
Correct |
29 ms |
34908 KB |
Output is correct |
7 |
Correct |
29 ms |
34900 KB |
Output is correct |
8 |
Correct |
28 ms |
34896 KB |
Output is correct |
9 |
Correct |
74 ms |
39256 KB |
Output is correct |
10 |
Correct |
91 ms |
40144 KB |
Output is correct |
11 |
Correct |
84 ms |
40132 KB |
Output is correct |
12 |
Correct |
102 ms |
40324 KB |
Output is correct |
13 |
Correct |
85 ms |
41416 KB |
Output is correct |
14 |
Correct |
80 ms |
39628 KB |
Output is correct |
15 |
Correct |
133 ms |
44368 KB |
Output is correct |
16 |
Correct |
127 ms |
44152 KB |
Output is correct |
17 |
Correct |
142 ms |
44492 KB |
Output is correct |
18 |
Correct |
126 ms |
45612 KB |
Output is correct |
19 |
Correct |
281 ms |
40720 KB |
Output is correct |
20 |
Correct |
529 ms |
45384 KB |
Output is correct |
21 |
Correct |
505 ms |
45476 KB |
Output is correct |
22 |
Correct |
539 ms |
45792 KB |
Output is correct |
23 |
Execution timed out |
2027 ms |
45364 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
34768 KB |
Output is correct |
2 |
Correct |
31 ms |
34640 KB |
Output is correct |
3 |
Execution timed out |
2005 ms |
44628 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
34768 KB |
Output is correct |
2 |
Correct |
31 ms |
34640 KB |
Output is correct |
3 |
Correct |
29 ms |
34652 KB |
Output is correct |
4 |
Correct |
29 ms |
34648 KB |
Output is correct |
5 |
Correct |
29 ms |
34896 KB |
Output is correct |
6 |
Correct |
29 ms |
34908 KB |
Output is correct |
7 |
Correct |
29 ms |
34900 KB |
Output is correct |
8 |
Correct |
28 ms |
34896 KB |
Output is correct |
9 |
Correct |
28 ms |
34652 KB |
Output is correct |
10 |
Correct |
27 ms |
34716 KB |
Output is correct |
11 |
Correct |
28 ms |
34908 KB |
Output is correct |
12 |
Correct |
28 ms |
34900 KB |
Output is correct |
13 |
Correct |
28 ms |
34908 KB |
Output is correct |
14 |
Correct |
28 ms |
34900 KB |
Output is correct |
15 |
Correct |
28 ms |
34904 KB |
Output is correct |
16 |
Correct |
29 ms |
34772 KB |
Output is correct |
17 |
Correct |
29 ms |
34820 KB |
Output is correct |
18 |
Correct |
28 ms |
34908 KB |
Output is correct |
19 |
Correct |
28 ms |
34916 KB |
Output is correct |
20 |
Correct |
27 ms |
34908 KB |
Output is correct |
21 |
Correct |
34 ms |
34724 KB |
Output is correct |
22 |
Correct |
29 ms |
34964 KB |
Output is correct |
23 |
Correct |
28 ms |
34908 KB |
Output is correct |
24 |
Correct |
28 ms |
34908 KB |
Output is correct |
25 |
Correct |
28 ms |
34900 KB |
Output is correct |
26 |
Correct |
28 ms |
34908 KB |
Output is correct |
27 |
Correct |
29 ms |
34936 KB |
Output is correct |
28 |
Correct |
30 ms |
34964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
34652 KB |
Output is correct |
2 |
Correct |
28 ms |
34768 KB |
Output is correct |
3 |
Correct |
31 ms |
34640 KB |
Output is correct |
4 |
Correct |
29 ms |
34652 KB |
Output is correct |
5 |
Correct |
29 ms |
34648 KB |
Output is correct |
6 |
Correct |
29 ms |
34896 KB |
Output is correct |
7 |
Correct |
29 ms |
34908 KB |
Output is correct |
8 |
Correct |
29 ms |
34900 KB |
Output is correct |
9 |
Correct |
28 ms |
34896 KB |
Output is correct |
10 |
Correct |
74 ms |
39256 KB |
Output is correct |
11 |
Correct |
91 ms |
40144 KB |
Output is correct |
12 |
Correct |
84 ms |
40132 KB |
Output is correct |
13 |
Correct |
102 ms |
40324 KB |
Output is correct |
14 |
Correct |
85 ms |
41416 KB |
Output is correct |
15 |
Correct |
27 ms |
34716 KB |
Output is correct |
16 |
Correct |
28 ms |
34908 KB |
Output is correct |
17 |
Correct |
28 ms |
34900 KB |
Output is correct |
18 |
Correct |
28 ms |
34908 KB |
Output is correct |
19 |
Correct |
28 ms |
34900 KB |
Output is correct |
20 |
Correct |
28 ms |
34904 KB |
Output is correct |
21 |
Correct |
29 ms |
34772 KB |
Output is correct |
22 |
Correct |
29 ms |
34820 KB |
Output is correct |
23 |
Correct |
28 ms |
34908 KB |
Output is correct |
24 |
Correct |
28 ms |
34916 KB |
Output is correct |
25 |
Correct |
27 ms |
34908 KB |
Output is correct |
26 |
Correct |
34 ms |
34724 KB |
Output is correct |
27 |
Correct |
29 ms |
34964 KB |
Output is correct |
28 |
Correct |
28 ms |
34908 KB |
Output is correct |
29 |
Correct |
28 ms |
34908 KB |
Output is correct |
30 |
Correct |
28 ms |
34900 KB |
Output is correct |
31 |
Correct |
28 ms |
34908 KB |
Output is correct |
32 |
Correct |
29 ms |
34936 KB |
Output is correct |
33 |
Correct |
30 ms |
34964 KB |
Output is correct |
34 |
Correct |
35 ms |
35604 KB |
Output is correct |
35 |
Correct |
90 ms |
40136 KB |
Output is correct |
36 |
Correct |
87 ms |
40136 KB |
Output is correct |
37 |
Correct |
106 ms |
40068 KB |
Output is correct |
38 |
Correct |
84 ms |
40156 KB |
Output is correct |
39 |
Correct |
91 ms |
39876 KB |
Output is correct |
40 |
Correct |
85 ms |
39620 KB |
Output is correct |
41 |
Correct |
89 ms |
40388 KB |
Output is correct |
42 |
Correct |
85 ms |
40188 KB |
Output is correct |
43 |
Correct |
115 ms |
40132 KB |
Output is correct |
44 |
Correct |
110 ms |
40392 KB |
Output is correct |
45 |
Execution timed out |
2037 ms |
43916 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
34768 KB |
Output is correct |
2 |
Correct |
31 ms |
34640 KB |
Output is correct |
3 |
Correct |
29 ms |
34652 KB |
Output is correct |
4 |
Correct |
29 ms |
34648 KB |
Output is correct |
5 |
Correct |
29 ms |
34896 KB |
Output is correct |
6 |
Correct |
29 ms |
34908 KB |
Output is correct |
7 |
Correct |
29 ms |
34900 KB |
Output is correct |
8 |
Correct |
28 ms |
34896 KB |
Output is correct |
9 |
Correct |
74 ms |
39256 KB |
Output is correct |
10 |
Correct |
91 ms |
40144 KB |
Output is correct |
11 |
Correct |
84 ms |
40132 KB |
Output is correct |
12 |
Correct |
102 ms |
40324 KB |
Output is correct |
13 |
Correct |
85 ms |
41416 KB |
Output is correct |
14 |
Correct |
80 ms |
39628 KB |
Output is correct |
15 |
Correct |
133 ms |
44368 KB |
Output is correct |
16 |
Correct |
127 ms |
44152 KB |
Output is correct |
17 |
Correct |
142 ms |
44492 KB |
Output is correct |
18 |
Correct |
126 ms |
45612 KB |
Output is correct |
19 |
Execution timed out |
2005 ms |
44628 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
34652 KB |
Output is correct |
2 |
Correct |
28 ms |
34768 KB |
Output is correct |
3 |
Correct |
31 ms |
34640 KB |
Output is correct |
4 |
Correct |
29 ms |
34652 KB |
Output is correct |
5 |
Correct |
29 ms |
34648 KB |
Output is correct |
6 |
Correct |
29 ms |
34896 KB |
Output is correct |
7 |
Correct |
29 ms |
34908 KB |
Output is correct |
8 |
Correct |
29 ms |
34900 KB |
Output is correct |
9 |
Correct |
28 ms |
34896 KB |
Output is correct |
10 |
Correct |
74 ms |
39256 KB |
Output is correct |
11 |
Correct |
91 ms |
40144 KB |
Output is correct |
12 |
Correct |
84 ms |
40132 KB |
Output is correct |
13 |
Correct |
102 ms |
40324 KB |
Output is correct |
14 |
Correct |
85 ms |
41416 KB |
Output is correct |
15 |
Correct |
80 ms |
39628 KB |
Output is correct |
16 |
Correct |
133 ms |
44368 KB |
Output is correct |
17 |
Correct |
127 ms |
44152 KB |
Output is correct |
18 |
Correct |
142 ms |
44492 KB |
Output is correct |
19 |
Correct |
126 ms |
45612 KB |
Output is correct |
20 |
Execution timed out |
2005 ms |
44628 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |