#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 25;
int t[MAXN], n, m;
array <int, 3> edges[MAXN];
int deg[MAXN];
vector <int> sub[MAXN]; int par[MAXN];
bool ok[MAXN];
vector <array <int, 3>> times[MAXN];
int sum = 0;
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++) edges[i] = {u[i], v[i], w[i]};
for (int i = 0; i < m; i++) t[i] = i;
sort(t, t + m, [&] (int &x, int &y) { return edges[x][2] < edges[y][2]; });
for (int i = 0; i < n; i++) {
sub[i].push_back(i);
par[i] = i;
times[i].push_back({-1, i, 0}); sum++;assert(sum <= 1e7);
}
for (int i = 0; i < m; i++) {
int a = edges[t[i]][0], b = edges[t[i]][1];
if (par[a] == par[b]) {
if (ok[par[a]]) {
deg[a]++; deg[b]++;
continue;
}
ok[par[a]] = 1;
for (auto j : sub[par[a]]) {
times[j].push_back({i, par[a], 1}); sum++;assert(sum <= 1e7);
}
deg[a]++; deg[b]++;
continue;
}
if (sub[par[a]].size() > sub[par[b]].size()) swap(a, b);
bool flag = ok[par[a]] || ok[par[b]];
flag |= deg[a] > 1 || deg[b] > 1;
if (!flag) {
int l = par[a];
for (auto j : sub[l]) {
times[j].push_back({i, par[b], 0}); sum++;assert(sum <= 1e7);
par[j] = par[b];
sub[par[b]].push_back(j);
}
sub[l].clear();
deg[a]++; deg[b]++;
continue;
}
if (!ok[par[b]]) {
ok[par[b]] = 1;
for (auto j : sub[par[b]]) {
times[j].push_back({i, par[b], 1}); sum++; assert(sum <= 1e7);
}
}
int l = par[a];
for (auto j : sub[l]) {
times[j].push_back({i, par[b], 1}); sum++;assert(sum <= 1e7);
par[j] = par[b];
sub[par[b]].push_back(j);
}
sub[l].clear();
deg[a]++; deg[b]++;
}
}
int getMinimumFuelCapacity (int x, int y) {
int l = 0, r = m - 1, ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
array <int, 3> ff = {mid + 1, (int)-1e9, (int)-1e9};
auto g = lower_bound(times[x].begin(), times[x].end(), ff) - times[x].begin();
auto h = lower_bound(times[y].begin(), times[y].end(), ff) - times[y].begin();
g--; h--;
if (times[x][g][1] != times[y][h][1]) {
l = mid + 1; continue;
}
if (!times[x][g][2] || !times[y][h][2]) {
l = mid + 1;
} else {
r = mid - 1; ans = mid;
}
}
return ans == -1 ? -1 : edges[t[ans]][2];
}/*
int main () {
int n, m;
cin >> n >> m;
vector <int> u, v, w;
for (int i = 0; i < m; i++) {
int a, b, c; cin >> a >> b >> c;
u.push_back(a); v.push_back(b); w.push_back(c);
}
init(n, m, u, v, w);
int x, y; cin >> x >> y;
cout << getMinimumFuelCapacity(x, y) << '\n';
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
3 ms |
12888 KB |
Output is correct |
6 |
Correct |
4 ms |
12888 KB |
Output is correct |
7 |
Correct |
3 ms |
13144 KB |
Output is correct |
8 |
Correct |
3 ms |
12892 KB |
Output is correct |
9 |
Correct |
92 ms |
31252 KB |
Output is correct |
10 |
Correct |
115 ms |
35272 KB |
Output is correct |
11 |
Correct |
95 ms |
34628 KB |
Output is correct |
12 |
Correct |
112 ms |
36040 KB |
Output is correct |
13 |
Correct |
62 ms |
25628 KB |
Output is correct |
14 |
Correct |
97 ms |
31436 KB |
Output is correct |
15 |
Correct |
234 ms |
38020 KB |
Output is correct |
16 |
Correct |
227 ms |
36744 KB |
Output is correct |
17 |
Correct |
252 ms |
38452 KB |
Output is correct |
18 |
Correct |
152 ms |
27344 KB |
Output is correct |
19 |
Correct |
104 ms |
20004 KB |
Output is correct |
20 |
Correct |
259 ms |
41136 KB |
Output is correct |
21 |
Correct |
312 ms |
40436 KB |
Output is correct |
22 |
Correct |
262 ms |
42160 KB |
Output is correct |
23 |
Correct |
185 ms |
31880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
156 ms |
24864 KB |
Output is correct |
4 |
Correct |
154 ms |
25220 KB |
Output is correct |
5 |
Correct |
179 ms |
25196 KB |
Output is correct |
6 |
Correct |
145 ms |
25144 KB |
Output is correct |
7 |
Correct |
147 ms |
25328 KB |
Output is correct |
8 |
Correct |
144 ms |
24780 KB |
Output is correct |
9 |
Correct |
148 ms |
25164 KB |
Output is correct |
10 |
Correct |
146 ms |
24952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
3 ms |
12888 KB |
Output is correct |
6 |
Correct |
4 ms |
12888 KB |
Output is correct |
7 |
Correct |
3 ms |
13144 KB |
Output is correct |
8 |
Correct |
3 ms |
12892 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
3 ms |
12888 KB |
Output is correct |
11 |
Correct |
4 ms |
12892 KB |
Output is correct |
12 |
Correct |
3 ms |
12904 KB |
Output is correct |
13 |
Correct |
3 ms |
12976 KB |
Output is correct |
14 |
Correct |
3 ms |
12896 KB |
Output is correct |
15 |
Correct |
4 ms |
12948 KB |
Output is correct |
16 |
Correct |
4 ms |
13144 KB |
Output is correct |
17 |
Correct |
3 ms |
12892 KB |
Output is correct |
18 |
Correct |
3 ms |
12892 KB |
Output is correct |
19 |
Correct |
3 ms |
12892 KB |
Output is correct |
20 |
Correct |
3 ms |
12980 KB |
Output is correct |
21 |
Correct |
3 ms |
12980 KB |
Output is correct |
22 |
Correct |
4 ms |
12888 KB |
Output is correct |
23 |
Correct |
3 ms |
12892 KB |
Output is correct |
24 |
Correct |
3 ms |
13148 KB |
Output is correct |
25 |
Correct |
3 ms |
12888 KB |
Output is correct |
26 |
Correct |
3 ms |
13148 KB |
Output is correct |
27 |
Correct |
3 ms |
12892 KB |
Output is correct |
28 |
Correct |
3 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
2 ms |
12888 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
3 ms |
12892 KB |
Output is correct |
6 |
Correct |
3 ms |
12888 KB |
Output is correct |
7 |
Correct |
4 ms |
12888 KB |
Output is correct |
8 |
Correct |
3 ms |
13144 KB |
Output is correct |
9 |
Correct |
3 ms |
12892 KB |
Output is correct |
10 |
Correct |
92 ms |
31252 KB |
Output is correct |
11 |
Correct |
115 ms |
35272 KB |
Output is correct |
12 |
Correct |
95 ms |
34628 KB |
Output is correct |
13 |
Correct |
112 ms |
36040 KB |
Output is correct |
14 |
Correct |
62 ms |
25628 KB |
Output is correct |
15 |
Correct |
3 ms |
12888 KB |
Output is correct |
16 |
Correct |
4 ms |
12892 KB |
Output is correct |
17 |
Correct |
3 ms |
12904 KB |
Output is correct |
18 |
Correct |
3 ms |
12976 KB |
Output is correct |
19 |
Correct |
3 ms |
12896 KB |
Output is correct |
20 |
Correct |
4 ms |
12948 KB |
Output is correct |
21 |
Correct |
4 ms |
13144 KB |
Output is correct |
22 |
Correct |
3 ms |
12892 KB |
Output is correct |
23 |
Correct |
3 ms |
12892 KB |
Output is correct |
24 |
Correct |
3 ms |
12892 KB |
Output is correct |
25 |
Correct |
3 ms |
12980 KB |
Output is correct |
26 |
Correct |
3 ms |
12980 KB |
Output is correct |
27 |
Correct |
4 ms |
12888 KB |
Output is correct |
28 |
Correct |
3 ms |
12892 KB |
Output is correct |
29 |
Correct |
3 ms |
13148 KB |
Output is correct |
30 |
Correct |
3 ms |
12888 KB |
Output is correct |
31 |
Correct |
3 ms |
13148 KB |
Output is correct |
32 |
Correct |
3 ms |
12892 KB |
Output is correct |
33 |
Correct |
3 ms |
12892 KB |
Output is correct |
34 |
Correct |
13 ms |
15452 KB |
Output is correct |
35 |
Correct |
109 ms |
36024 KB |
Output is correct |
36 |
Correct |
118 ms |
35788 KB |
Output is correct |
37 |
Correct |
130 ms |
35272 KB |
Output is correct |
38 |
Correct |
99 ms |
34024 KB |
Output is correct |
39 |
Correct |
101 ms |
33736 KB |
Output is correct |
40 |
Correct |
88 ms |
31560 KB |
Output is correct |
41 |
Correct |
143 ms |
39212 KB |
Output is correct |
42 |
Correct |
116 ms |
37876 KB |
Output is correct |
43 |
Correct |
62 ms |
24416 KB |
Output is correct |
44 |
Correct |
99 ms |
33536 KB |
Output is correct |
45 |
Correct |
78 ms |
26300 KB |
Output is correct |
46 |
Correct |
109 ms |
35560 KB |
Output is correct |
47 |
Correct |
109 ms |
30864 KB |
Output is correct |
48 |
Correct |
81 ms |
26572 KB |
Output is correct |
49 |
Correct |
51 ms |
17792 KB |
Output is correct |
50 |
Correct |
41 ms |
17084 KB |
Output is correct |
51 |
Correct |
65 ms |
23760 KB |
Output is correct |
52 |
Correct |
130 ms |
37880 KB |
Output is correct |
53 |
Correct |
136 ms |
33736 KB |
Output is correct |
54 |
Correct |
162 ms |
41256 KB |
Output is correct |
55 |
Correct |
62 ms |
25108 KB |
Output is correct |
56 |
Correct |
106 ms |
29640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
3 ms |
12888 KB |
Output is correct |
6 |
Correct |
4 ms |
12888 KB |
Output is correct |
7 |
Correct |
3 ms |
13144 KB |
Output is correct |
8 |
Correct |
3 ms |
12892 KB |
Output is correct |
9 |
Correct |
92 ms |
31252 KB |
Output is correct |
10 |
Correct |
115 ms |
35272 KB |
Output is correct |
11 |
Correct |
95 ms |
34628 KB |
Output is correct |
12 |
Correct |
112 ms |
36040 KB |
Output is correct |
13 |
Correct |
62 ms |
25628 KB |
Output is correct |
14 |
Correct |
97 ms |
31436 KB |
Output is correct |
15 |
Correct |
234 ms |
38020 KB |
Output is correct |
16 |
Correct |
227 ms |
36744 KB |
Output is correct |
17 |
Correct |
252 ms |
38452 KB |
Output is correct |
18 |
Correct |
152 ms |
27344 KB |
Output is correct |
19 |
Correct |
156 ms |
24864 KB |
Output is correct |
20 |
Correct |
154 ms |
25220 KB |
Output is correct |
21 |
Correct |
179 ms |
25196 KB |
Output is correct |
22 |
Correct |
145 ms |
25144 KB |
Output is correct |
23 |
Correct |
147 ms |
25328 KB |
Output is correct |
24 |
Correct |
144 ms |
24780 KB |
Output is correct |
25 |
Correct |
148 ms |
25164 KB |
Output is correct |
26 |
Correct |
146 ms |
24952 KB |
Output is correct |
27 |
Correct |
3 ms |
12888 KB |
Output is correct |
28 |
Correct |
4 ms |
12892 KB |
Output is correct |
29 |
Correct |
3 ms |
12904 KB |
Output is correct |
30 |
Correct |
3 ms |
12976 KB |
Output is correct |
31 |
Correct |
3 ms |
12896 KB |
Output is correct |
32 |
Correct |
4 ms |
12948 KB |
Output is correct |
33 |
Correct |
4 ms |
13144 KB |
Output is correct |
34 |
Correct |
3 ms |
12892 KB |
Output is correct |
35 |
Correct |
3 ms |
12892 KB |
Output is correct |
36 |
Correct |
13 ms |
15452 KB |
Output is correct |
37 |
Correct |
109 ms |
36024 KB |
Output is correct |
38 |
Correct |
118 ms |
35788 KB |
Output is correct |
39 |
Correct |
130 ms |
35272 KB |
Output is correct |
40 |
Correct |
99 ms |
34024 KB |
Output is correct |
41 |
Correct |
101 ms |
33736 KB |
Output is correct |
42 |
Correct |
88 ms |
31560 KB |
Output is correct |
43 |
Correct |
143 ms |
39212 KB |
Output is correct |
44 |
Correct |
116 ms |
37876 KB |
Output is correct |
45 |
Correct |
62 ms |
24416 KB |
Output is correct |
46 |
Correct |
99 ms |
33536 KB |
Output is correct |
47 |
Correct |
22 ms |
15704 KB |
Output is correct |
48 |
Correct |
294 ms |
38644 KB |
Output is correct |
49 |
Correct |
262 ms |
38036 KB |
Output is correct |
50 |
Correct |
241 ms |
37892 KB |
Output is correct |
51 |
Correct |
232 ms |
37184 KB |
Output is correct |
52 |
Correct |
234 ms |
35452 KB |
Output is correct |
53 |
Correct |
179 ms |
29884 KB |
Output is correct |
54 |
Correct |
259 ms |
40808 KB |
Output is correct |
55 |
Correct |
247 ms |
40624 KB |
Output is correct |
56 |
Correct |
179 ms |
28024 KB |
Output is correct |
57 |
Correct |
255 ms |
36404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12892 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
2 ms |
12888 KB |
Output is correct |
4 |
Correct |
3 ms |
12892 KB |
Output is correct |
5 |
Correct |
3 ms |
12892 KB |
Output is correct |
6 |
Correct |
3 ms |
12888 KB |
Output is correct |
7 |
Correct |
4 ms |
12888 KB |
Output is correct |
8 |
Correct |
3 ms |
13144 KB |
Output is correct |
9 |
Correct |
3 ms |
12892 KB |
Output is correct |
10 |
Correct |
92 ms |
31252 KB |
Output is correct |
11 |
Correct |
115 ms |
35272 KB |
Output is correct |
12 |
Correct |
95 ms |
34628 KB |
Output is correct |
13 |
Correct |
112 ms |
36040 KB |
Output is correct |
14 |
Correct |
62 ms |
25628 KB |
Output is correct |
15 |
Correct |
97 ms |
31436 KB |
Output is correct |
16 |
Correct |
234 ms |
38020 KB |
Output is correct |
17 |
Correct |
227 ms |
36744 KB |
Output is correct |
18 |
Correct |
252 ms |
38452 KB |
Output is correct |
19 |
Correct |
152 ms |
27344 KB |
Output is correct |
20 |
Correct |
156 ms |
24864 KB |
Output is correct |
21 |
Correct |
154 ms |
25220 KB |
Output is correct |
22 |
Correct |
179 ms |
25196 KB |
Output is correct |
23 |
Correct |
145 ms |
25144 KB |
Output is correct |
24 |
Correct |
147 ms |
25328 KB |
Output is correct |
25 |
Correct |
144 ms |
24780 KB |
Output is correct |
26 |
Correct |
148 ms |
25164 KB |
Output is correct |
27 |
Correct |
146 ms |
24952 KB |
Output is correct |
28 |
Correct |
3 ms |
12888 KB |
Output is correct |
29 |
Correct |
4 ms |
12892 KB |
Output is correct |
30 |
Correct |
3 ms |
12904 KB |
Output is correct |
31 |
Correct |
3 ms |
12976 KB |
Output is correct |
32 |
Correct |
3 ms |
12896 KB |
Output is correct |
33 |
Correct |
4 ms |
12948 KB |
Output is correct |
34 |
Correct |
4 ms |
13144 KB |
Output is correct |
35 |
Correct |
3 ms |
12892 KB |
Output is correct |
36 |
Correct |
3 ms |
12892 KB |
Output is correct |
37 |
Correct |
13 ms |
15452 KB |
Output is correct |
38 |
Correct |
109 ms |
36024 KB |
Output is correct |
39 |
Correct |
118 ms |
35788 KB |
Output is correct |
40 |
Correct |
130 ms |
35272 KB |
Output is correct |
41 |
Correct |
99 ms |
34024 KB |
Output is correct |
42 |
Correct |
101 ms |
33736 KB |
Output is correct |
43 |
Correct |
88 ms |
31560 KB |
Output is correct |
44 |
Correct |
143 ms |
39212 KB |
Output is correct |
45 |
Correct |
116 ms |
37876 KB |
Output is correct |
46 |
Correct |
62 ms |
24416 KB |
Output is correct |
47 |
Correct |
99 ms |
33536 KB |
Output is correct |
48 |
Correct |
22 ms |
15704 KB |
Output is correct |
49 |
Correct |
294 ms |
38644 KB |
Output is correct |
50 |
Correct |
262 ms |
38036 KB |
Output is correct |
51 |
Correct |
241 ms |
37892 KB |
Output is correct |
52 |
Correct |
232 ms |
37184 KB |
Output is correct |
53 |
Correct |
234 ms |
35452 KB |
Output is correct |
54 |
Correct |
179 ms |
29884 KB |
Output is correct |
55 |
Correct |
259 ms |
40808 KB |
Output is correct |
56 |
Correct |
247 ms |
40624 KB |
Output is correct |
57 |
Correct |
179 ms |
28024 KB |
Output is correct |
58 |
Correct |
255 ms |
36404 KB |
Output is correct |
59 |
Correct |
104 ms |
20004 KB |
Output is correct |
60 |
Correct |
259 ms |
41136 KB |
Output is correct |
61 |
Correct |
312 ms |
40436 KB |
Output is correct |
62 |
Correct |
262 ms |
42160 KB |
Output is correct |
63 |
Correct |
185 ms |
31880 KB |
Output is correct |
64 |
Correct |
3 ms |
12892 KB |
Output is correct |
65 |
Correct |
3 ms |
12980 KB |
Output is correct |
66 |
Correct |
3 ms |
12980 KB |
Output is correct |
67 |
Correct |
4 ms |
12888 KB |
Output is correct |
68 |
Correct |
3 ms |
12892 KB |
Output is correct |
69 |
Correct |
3 ms |
13148 KB |
Output is correct |
70 |
Correct |
3 ms |
12888 KB |
Output is correct |
71 |
Correct |
3 ms |
13148 KB |
Output is correct |
72 |
Correct |
3 ms |
12892 KB |
Output is correct |
73 |
Correct |
3 ms |
12892 KB |
Output is correct |
74 |
Correct |
78 ms |
26300 KB |
Output is correct |
75 |
Correct |
109 ms |
35560 KB |
Output is correct |
76 |
Correct |
109 ms |
30864 KB |
Output is correct |
77 |
Correct |
81 ms |
26572 KB |
Output is correct |
78 |
Correct |
51 ms |
17792 KB |
Output is correct |
79 |
Correct |
41 ms |
17084 KB |
Output is correct |
80 |
Correct |
65 ms |
23760 KB |
Output is correct |
81 |
Correct |
130 ms |
37880 KB |
Output is correct |
82 |
Correct |
136 ms |
33736 KB |
Output is correct |
83 |
Correct |
162 ms |
41256 KB |
Output is correct |
84 |
Correct |
62 ms |
25108 KB |
Output is correct |
85 |
Correct |
106 ms |
29640 KB |
Output is correct |
86 |
Correct |
54 ms |
19784 KB |
Output is correct |
87 |
Correct |
247 ms |
41400 KB |
Output is correct |
88 |
Correct |
254 ms |
41780 KB |
Output is correct |
89 |
Correct |
181 ms |
32492 KB |
Output is correct |
90 |
Correct |
144 ms |
24960 KB |
Output is correct |
91 |
Correct |
151 ms |
25960 KB |
Output is correct |
92 |
Correct |
166 ms |
31280 KB |
Output is correct |
93 |
Correct |
246 ms |
45672 KB |
Output is correct |
94 |
Correct |
269 ms |
42484 KB |
Output is correct |
95 |
Correct |
299 ms |
49944 KB |
Output is correct |
96 |
Correct |
160 ms |
31968 KB |
Output is correct |
97 |
Correct |
220 ms |
36568 KB |
Output is correct |