#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 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];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
105 ms |
25372 KB |
Output is correct |
10 |
Correct |
102 ms |
29388 KB |
Output is correct |
11 |
Correct |
122 ms |
28872 KB |
Output is correct |
12 |
Correct |
111 ms |
30412 KB |
Output is correct |
13 |
Correct |
71 ms |
19744 KB |
Output is correct |
14 |
Correct |
103 ms |
25388 KB |
Output is correct |
15 |
Correct |
243 ms |
31816 KB |
Output is correct |
16 |
Correct |
247 ms |
30972 KB |
Output is correct |
17 |
Correct |
251 ms |
32560 KB |
Output is correct |
18 |
Correct |
163 ms |
21860 KB |
Output is correct |
19 |
Correct |
108 ms |
13772 KB |
Output is correct |
20 |
Correct |
243 ms |
35268 KB |
Output is correct |
21 |
Correct |
236 ms |
34556 KB |
Output is correct |
22 |
Correct |
251 ms |
36268 KB |
Output is correct |
23 |
Correct |
171 ms |
26012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
164 ms |
19080 KB |
Output is correct |
4 |
Correct |
153 ms |
19384 KB |
Output is correct |
5 |
Correct |
155 ms |
19464 KB |
Output is correct |
6 |
Correct |
150 ms |
19536 KB |
Output is correct |
7 |
Correct |
155 ms |
19532 KB |
Output is correct |
8 |
Correct |
146 ms |
19064 KB |
Output is correct |
9 |
Correct |
156 ms |
19368 KB |
Output is correct |
10 |
Correct |
146 ms |
19084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
1 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
2 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
2 ms |
6748 KB |
Output is correct |
15 |
Correct |
2 ms |
6816 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6840 KB |
Output is correct |
20 |
Correct |
2 ms |
6836 KB |
Output is correct |
21 |
Correct |
3 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
7004 KB |
Output is correct |
25 |
Correct |
2 ms |
6744 KB |
Output is correct |
26 |
Correct |
2 ms |
7004 KB |
Output is correct |
27 |
Correct |
2 ms |
6744 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6744 KB |
Output is correct |
10 |
Correct |
105 ms |
25372 KB |
Output is correct |
11 |
Correct |
102 ms |
29388 KB |
Output is correct |
12 |
Correct |
122 ms |
28872 KB |
Output is correct |
13 |
Correct |
111 ms |
30412 KB |
Output is correct |
14 |
Correct |
71 ms |
19744 KB |
Output is correct |
15 |
Correct |
2 ms |
6748 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
2 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6816 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
2 ms |
6748 KB |
Output is correct |
24 |
Correct |
2 ms |
6840 KB |
Output is correct |
25 |
Correct |
2 ms |
6836 KB |
Output is correct |
26 |
Correct |
3 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6744 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
7004 KB |
Output is correct |
30 |
Correct |
2 ms |
6744 KB |
Output is correct |
31 |
Correct |
2 ms |
7004 KB |
Output is correct |
32 |
Correct |
2 ms |
6744 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
10 ms |
9308 KB |
Output is correct |
35 |
Correct |
108 ms |
30344 KB |
Output is correct |
36 |
Correct |
108 ms |
29916 KB |
Output is correct |
37 |
Correct |
107 ms |
29384 KB |
Output is correct |
38 |
Correct |
112 ms |
28516 KB |
Output is correct |
39 |
Correct |
100 ms |
28108 KB |
Output is correct |
40 |
Correct |
94 ms |
25676 KB |
Output is correct |
41 |
Correct |
125 ms |
33100 KB |
Output is correct |
42 |
Correct |
137 ms |
31932 KB |
Output is correct |
43 |
Correct |
79 ms |
18636 KB |
Output is correct |
44 |
Correct |
147 ms |
27896 KB |
Output is correct |
45 |
Runtime error |
42 ms |
21852 KB |
Execution killed with signal 11 |
46 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
105 ms |
25372 KB |
Output is correct |
10 |
Correct |
102 ms |
29388 KB |
Output is correct |
11 |
Correct |
122 ms |
28872 KB |
Output is correct |
12 |
Correct |
111 ms |
30412 KB |
Output is correct |
13 |
Correct |
71 ms |
19744 KB |
Output is correct |
14 |
Correct |
103 ms |
25388 KB |
Output is correct |
15 |
Correct |
243 ms |
31816 KB |
Output is correct |
16 |
Correct |
247 ms |
30972 KB |
Output is correct |
17 |
Correct |
251 ms |
32560 KB |
Output is correct |
18 |
Correct |
163 ms |
21860 KB |
Output is correct |
19 |
Correct |
164 ms |
19080 KB |
Output is correct |
20 |
Correct |
153 ms |
19384 KB |
Output is correct |
21 |
Correct |
155 ms |
19464 KB |
Output is correct |
22 |
Correct |
150 ms |
19536 KB |
Output is correct |
23 |
Correct |
155 ms |
19532 KB |
Output is correct |
24 |
Correct |
146 ms |
19064 KB |
Output is correct |
25 |
Correct |
156 ms |
19368 KB |
Output is correct |
26 |
Correct |
146 ms |
19084 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
2 ms |
6748 KB |
Output is correct |
31 |
Correct |
2 ms |
6748 KB |
Output is correct |
32 |
Correct |
2 ms |
6816 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
2 ms |
6748 KB |
Output is correct |
35 |
Correct |
2 ms |
6748 KB |
Output is correct |
36 |
Correct |
10 ms |
9308 KB |
Output is correct |
37 |
Correct |
108 ms |
30344 KB |
Output is correct |
38 |
Correct |
108 ms |
29916 KB |
Output is correct |
39 |
Correct |
107 ms |
29384 KB |
Output is correct |
40 |
Correct |
112 ms |
28516 KB |
Output is correct |
41 |
Correct |
100 ms |
28108 KB |
Output is correct |
42 |
Correct |
94 ms |
25676 KB |
Output is correct |
43 |
Correct |
125 ms |
33100 KB |
Output is correct |
44 |
Correct |
137 ms |
31932 KB |
Output is correct |
45 |
Correct |
79 ms |
18636 KB |
Output is correct |
46 |
Correct |
147 ms |
27896 KB |
Output is correct |
47 |
Correct |
22 ms |
9816 KB |
Output is correct |
48 |
Correct |
276 ms |
32940 KB |
Output is correct |
49 |
Correct |
245 ms |
32268 KB |
Output is correct |
50 |
Correct |
249 ms |
32264 KB |
Output is correct |
51 |
Correct |
261 ms |
31292 KB |
Output is correct |
52 |
Correct |
260 ms |
29564 KB |
Output is correct |
53 |
Correct |
186 ms |
23824 KB |
Output is correct |
54 |
Correct |
298 ms |
35084 KB |
Output is correct |
55 |
Correct |
266 ms |
34956 KB |
Output is correct |
56 |
Correct |
164 ms |
22228 KB |
Output is correct |
57 |
Correct |
240 ms |
30512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6748 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6744 KB |
Output is correct |
10 |
Correct |
105 ms |
25372 KB |
Output is correct |
11 |
Correct |
102 ms |
29388 KB |
Output is correct |
12 |
Correct |
122 ms |
28872 KB |
Output is correct |
13 |
Correct |
111 ms |
30412 KB |
Output is correct |
14 |
Correct |
71 ms |
19744 KB |
Output is correct |
15 |
Correct |
103 ms |
25388 KB |
Output is correct |
16 |
Correct |
243 ms |
31816 KB |
Output is correct |
17 |
Correct |
247 ms |
30972 KB |
Output is correct |
18 |
Correct |
251 ms |
32560 KB |
Output is correct |
19 |
Correct |
163 ms |
21860 KB |
Output is correct |
20 |
Correct |
164 ms |
19080 KB |
Output is correct |
21 |
Correct |
153 ms |
19384 KB |
Output is correct |
22 |
Correct |
155 ms |
19464 KB |
Output is correct |
23 |
Correct |
150 ms |
19536 KB |
Output is correct |
24 |
Correct |
155 ms |
19532 KB |
Output is correct |
25 |
Correct |
146 ms |
19064 KB |
Output is correct |
26 |
Correct |
156 ms |
19368 KB |
Output is correct |
27 |
Correct |
146 ms |
19084 KB |
Output is correct |
28 |
Correct |
2 ms |
6748 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
2 ms |
6748 KB |
Output is correct |
31 |
Correct |
2 ms |
6748 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
2 ms |
6816 KB |
Output is correct |
34 |
Correct |
2 ms |
6748 KB |
Output is correct |
35 |
Correct |
2 ms |
6748 KB |
Output is correct |
36 |
Correct |
2 ms |
6748 KB |
Output is correct |
37 |
Correct |
10 ms |
9308 KB |
Output is correct |
38 |
Correct |
108 ms |
30344 KB |
Output is correct |
39 |
Correct |
108 ms |
29916 KB |
Output is correct |
40 |
Correct |
107 ms |
29384 KB |
Output is correct |
41 |
Correct |
112 ms |
28516 KB |
Output is correct |
42 |
Correct |
100 ms |
28108 KB |
Output is correct |
43 |
Correct |
94 ms |
25676 KB |
Output is correct |
44 |
Correct |
125 ms |
33100 KB |
Output is correct |
45 |
Correct |
137 ms |
31932 KB |
Output is correct |
46 |
Correct |
79 ms |
18636 KB |
Output is correct |
47 |
Correct |
147 ms |
27896 KB |
Output is correct |
48 |
Correct |
22 ms |
9816 KB |
Output is correct |
49 |
Correct |
276 ms |
32940 KB |
Output is correct |
50 |
Correct |
245 ms |
32268 KB |
Output is correct |
51 |
Correct |
249 ms |
32264 KB |
Output is correct |
52 |
Correct |
261 ms |
31292 KB |
Output is correct |
53 |
Correct |
260 ms |
29564 KB |
Output is correct |
54 |
Correct |
186 ms |
23824 KB |
Output is correct |
55 |
Correct |
298 ms |
35084 KB |
Output is correct |
56 |
Correct |
266 ms |
34956 KB |
Output is correct |
57 |
Correct |
164 ms |
22228 KB |
Output is correct |
58 |
Correct |
240 ms |
30512 KB |
Output is correct |
59 |
Correct |
108 ms |
13772 KB |
Output is correct |
60 |
Correct |
243 ms |
35268 KB |
Output is correct |
61 |
Correct |
236 ms |
34556 KB |
Output is correct |
62 |
Correct |
251 ms |
36268 KB |
Output is correct |
63 |
Correct |
171 ms |
26012 KB |
Output is correct |
64 |
Correct |
2 ms |
6840 KB |
Output is correct |
65 |
Correct |
2 ms |
6836 KB |
Output is correct |
66 |
Correct |
3 ms |
6748 KB |
Output is correct |
67 |
Correct |
2 ms |
6744 KB |
Output is correct |
68 |
Correct |
2 ms |
6748 KB |
Output is correct |
69 |
Correct |
2 ms |
7004 KB |
Output is correct |
70 |
Correct |
2 ms |
6744 KB |
Output is correct |
71 |
Correct |
2 ms |
7004 KB |
Output is correct |
72 |
Correct |
2 ms |
6744 KB |
Output is correct |
73 |
Correct |
2 ms |
6748 KB |
Output is correct |
74 |
Runtime error |
42 ms |
21852 KB |
Execution killed with signal 11 |
75 |
Halted |
0 ms |
0 KB |
- |