#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include "swap.h"
const int n0 = 2e5 + 123;
int n, m, ans[n0], deg[n0], inf;
vector <array <int, 3>> e;
vector <int> dsu[n0];
vector <array <int, 2>> p[n0];
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N, m = M;
for (int i = 0; i < m; i++)
e.pb({W[i], U[i], V[i]});
sort(all(e));
memset(& ans, 0x3f, sizeof(ans));
inf = ans[0];
for (int i = 0; i < n; i++)
p[i].pb({0, i}), dsu[i].pb(i);
for (auto i : e) {
int w = i[0], u = i[1], v = i[2];
int vc = p[v].back()[1], uc = p[u].back()[1];
if (vc == uc)
ans[vc] = min(ans[vc], w);
else {
if (SZ(dsu[vc]) < SZ(dsu[uc])) {
swap(vc, uc);
swap(v, u);
}
deg[v]++, deg[u]++;
ans[vc] = min(ans[vc], max(w, ans[uc]));
if (deg[v] > 2 || deg[u] > 2)
ans[vc] = min(ans[vc], w);
for (int x : dsu[uc]) {
dsu[vc].pb(x);
p[x].pb({w, vc});
}
}
}
}
int getMinimumFuelCapacity(int x, int y) {
int i = SZ(p[x]) - 1, j = SZ(p[y]) - 1, mt = inf;
while (i >= 0 && j >= 0 && p[x][i][1] == p[y][j][1]) {
mt = min(mt, max({ans[p[x][i][1]], p[x][i][0], p[y][j][0]}));
i--, j--;
}
return (mt == inf) ? -1 : mt;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10496 KB |
Output is correct |
2 |
Correct |
7 ms |
10496 KB |
Output is correct |
3 |
Correct |
7 ms |
10496 KB |
Output is correct |
4 |
Correct |
7 ms |
10624 KB |
Output is correct |
5 |
Correct |
9 ms |
10656 KB |
Output is correct |
6 |
Correct |
8 ms |
10624 KB |
Output is correct |
7 |
Correct |
7 ms |
10624 KB |
Output is correct |
8 |
Correct |
8 ms |
10624 KB |
Output is correct |
9 |
Correct |
170 ms |
26916 KB |
Output is correct |
10 |
Correct |
215 ms |
30188 KB |
Output is correct |
11 |
Correct |
211 ms |
29840 KB |
Output is correct |
12 |
Correct |
226 ms |
31044 KB |
Output is correct |
13 |
Correct |
142 ms |
23660 KB |
Output is correct |
14 |
Correct |
175 ms |
26860 KB |
Output is correct |
15 |
Correct |
316 ms |
32376 KB |
Output is correct |
16 |
Correct |
309 ms |
31900 KB |
Output is correct |
17 |
Correct |
330 ms |
33272 KB |
Output is correct |
18 |
Correct |
232 ms |
25552 KB |
Output is correct |
19 |
Correct |
95 ms |
17080 KB |
Output is correct |
20 |
Correct |
313 ms |
33644 KB |
Output is correct |
21 |
Correct |
315 ms |
33332 KB |
Output is correct |
22 |
Correct |
334 ms |
34384 KB |
Output is correct |
23 |
Correct |
239 ms |
26836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10496 KB |
Output is correct |
2 |
Correct |
7 ms |
10496 KB |
Output is correct |
3 |
Correct |
208 ms |
24080 KB |
Output is correct |
4 |
Correct |
209 ms |
24532 KB |
Output is correct |
5 |
Correct |
207 ms |
24448 KB |
Output is correct |
6 |
Correct |
203 ms |
24404 KB |
Output is correct |
7 |
Correct |
212 ms |
24484 KB |
Output is correct |
8 |
Correct |
198 ms |
24200 KB |
Output is correct |
9 |
Correct |
204 ms |
24296 KB |
Output is correct |
10 |
Correct |
200 ms |
24104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10496 KB |
Output is correct |
2 |
Correct |
7 ms |
10496 KB |
Output is correct |
3 |
Correct |
7 ms |
10496 KB |
Output is correct |
4 |
Correct |
7 ms |
10496 KB |
Output is correct |
5 |
Correct |
7 ms |
10624 KB |
Output is correct |
6 |
Correct |
9 ms |
10656 KB |
Output is correct |
7 |
Correct |
8 ms |
10624 KB |
Output is correct |
8 |
Correct |
7 ms |
10624 KB |
Output is correct |
9 |
Correct |
8 ms |
10624 KB |
Output is correct |
10 |
Correct |
7 ms |
10624 KB |
Output is correct |
11 |
Correct |
9 ms |
10624 KB |
Output is correct |
12 |
Correct |
8 ms |
10624 KB |
Output is correct |
13 |
Correct |
7 ms |
10624 KB |
Output is correct |
14 |
Correct |
8 ms |
10624 KB |
Output is correct |
15 |
Correct |
8 ms |
10624 KB |
Output is correct |
16 |
Correct |
7 ms |
10624 KB |
Output is correct |
17 |
Correct |
8 ms |
10624 KB |
Output is correct |
18 |
Correct |
8 ms |
10624 KB |
Output is correct |
19 |
Correct |
8 ms |
10624 KB |
Output is correct |
20 |
Correct |
9 ms |
10624 KB |
Output is correct |
21 |
Correct |
7 ms |
10624 KB |
Output is correct |
22 |
Correct |
8 ms |
10624 KB |
Output is correct |
23 |
Correct |
7 ms |
10624 KB |
Output is correct |
24 |
Correct |
8 ms |
10752 KB |
Output is correct |
25 |
Correct |
8 ms |
10624 KB |
Output is correct |
26 |
Correct |
8 ms |
10752 KB |
Output is correct |
27 |
Correct |
7 ms |
10624 KB |
Output is correct |
28 |
Correct |
8 ms |
10624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10496 KB |
Output is correct |
2 |
Correct |
7 ms |
10496 KB |
Output is correct |
3 |
Correct |
7 ms |
10496 KB |
Output is correct |
4 |
Correct |
7 ms |
10496 KB |
Output is correct |
5 |
Correct |
7 ms |
10624 KB |
Output is correct |
6 |
Correct |
9 ms |
10656 KB |
Output is correct |
7 |
Correct |
8 ms |
10624 KB |
Output is correct |
8 |
Correct |
7 ms |
10624 KB |
Output is correct |
9 |
Correct |
8 ms |
10624 KB |
Output is correct |
10 |
Correct |
170 ms |
26916 KB |
Output is correct |
11 |
Correct |
215 ms |
30188 KB |
Output is correct |
12 |
Correct |
211 ms |
29840 KB |
Output is correct |
13 |
Correct |
226 ms |
31044 KB |
Output is correct |
14 |
Correct |
142 ms |
23660 KB |
Output is correct |
15 |
Correct |
7 ms |
10624 KB |
Output is correct |
16 |
Correct |
9 ms |
10624 KB |
Output is correct |
17 |
Correct |
8 ms |
10624 KB |
Output is correct |
18 |
Correct |
7 ms |
10624 KB |
Output is correct |
19 |
Correct |
8 ms |
10624 KB |
Output is correct |
20 |
Correct |
8 ms |
10624 KB |
Output is correct |
21 |
Correct |
7 ms |
10624 KB |
Output is correct |
22 |
Correct |
8 ms |
10624 KB |
Output is correct |
23 |
Correct |
8 ms |
10624 KB |
Output is correct |
24 |
Correct |
22 ms |
12864 KB |
Output is correct |
25 |
Correct |
236 ms |
30828 KB |
Output is correct |
26 |
Correct |
226 ms |
30828 KB |
Output is correct |
27 |
Correct |
219 ms |
30188 KB |
Output is correct |
28 |
Correct |
219 ms |
29292 KB |
Output is correct |
29 |
Correct |
213 ms |
29124 KB |
Output is correct |
30 |
Correct |
178 ms |
27244 KB |
Output is correct |
31 |
Correct |
239 ms |
31340 KB |
Output is correct |
32 |
Correct |
232 ms |
31468 KB |
Output is correct |
33 |
Correct |
127 ms |
22860 KB |
Output is correct |
34 |
Correct |
208 ms |
28652 KB |
Output is correct |
35 |
Correct |
8 ms |
10624 KB |
Output is correct |
36 |
Correct |
9 ms |
10624 KB |
Output is correct |
37 |
Correct |
7 ms |
10624 KB |
Output is correct |
38 |
Correct |
8 ms |
10624 KB |
Output is correct |
39 |
Correct |
7 ms |
10624 KB |
Output is correct |
40 |
Correct |
8 ms |
10752 KB |
Output is correct |
41 |
Correct |
8 ms |
10624 KB |
Output is correct |
42 |
Correct |
8 ms |
10752 KB |
Output is correct |
43 |
Correct |
7 ms |
10624 KB |
Output is correct |
44 |
Correct |
8 ms |
10624 KB |
Output is correct |
45 |
Correct |
176 ms |
23916 KB |
Output is correct |
46 |
Correct |
221 ms |
30700 KB |
Output is correct |
47 |
Correct |
196 ms |
27116 KB |
Output is correct |
48 |
Correct |
168 ms |
24300 KB |
Output is correct |
49 |
Correct |
95 ms |
16656 KB |
Output is correct |
50 |
Correct |
86 ms |
15548 KB |
Output is correct |
51 |
Correct |
140 ms |
21484 KB |
Output is correct |
52 |
Correct |
267 ms |
32000 KB |
Output is correct |
53 |
Correct |
249 ms |
27748 KB |
Output is correct |
54 |
Correct |
313 ms |
34788 KB |
Output is correct |
55 |
Correct |
134 ms |
23148 KB |
Output is correct |
56 |
Correct |
224 ms |
26856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10496 KB |
Output is correct |
2 |
Correct |
7 ms |
10496 KB |
Output is correct |
3 |
Correct |
7 ms |
10496 KB |
Output is correct |
4 |
Correct |
7 ms |
10624 KB |
Output is correct |
5 |
Correct |
9 ms |
10656 KB |
Output is correct |
6 |
Correct |
8 ms |
10624 KB |
Output is correct |
7 |
Correct |
7 ms |
10624 KB |
Output is correct |
8 |
Correct |
8 ms |
10624 KB |
Output is correct |
9 |
Correct |
170 ms |
26916 KB |
Output is correct |
10 |
Correct |
215 ms |
30188 KB |
Output is correct |
11 |
Correct |
211 ms |
29840 KB |
Output is correct |
12 |
Correct |
226 ms |
31044 KB |
Output is correct |
13 |
Correct |
142 ms |
23660 KB |
Output is correct |
14 |
Correct |
175 ms |
26860 KB |
Output is correct |
15 |
Correct |
316 ms |
32376 KB |
Output is correct |
16 |
Correct |
309 ms |
31900 KB |
Output is correct |
17 |
Correct |
330 ms |
33272 KB |
Output is correct |
18 |
Correct |
232 ms |
25552 KB |
Output is correct |
19 |
Correct |
208 ms |
24080 KB |
Output is correct |
20 |
Correct |
209 ms |
24532 KB |
Output is correct |
21 |
Correct |
207 ms |
24448 KB |
Output is correct |
22 |
Correct |
203 ms |
24404 KB |
Output is correct |
23 |
Correct |
212 ms |
24484 KB |
Output is correct |
24 |
Correct |
198 ms |
24200 KB |
Output is correct |
25 |
Correct |
204 ms |
24296 KB |
Output is correct |
26 |
Correct |
200 ms |
24104 KB |
Output is correct |
27 |
Correct |
7 ms |
10624 KB |
Output is correct |
28 |
Correct |
9 ms |
10624 KB |
Output is correct |
29 |
Correct |
8 ms |
10624 KB |
Output is correct |
30 |
Correct |
7 ms |
10624 KB |
Output is correct |
31 |
Correct |
8 ms |
10624 KB |
Output is correct |
32 |
Correct |
8 ms |
10624 KB |
Output is correct |
33 |
Correct |
7 ms |
10624 KB |
Output is correct |
34 |
Correct |
8 ms |
10624 KB |
Output is correct |
35 |
Correct |
8 ms |
10624 KB |
Output is correct |
36 |
Correct |
22 ms |
12864 KB |
Output is correct |
37 |
Correct |
236 ms |
30828 KB |
Output is correct |
38 |
Correct |
226 ms |
30828 KB |
Output is correct |
39 |
Correct |
219 ms |
30188 KB |
Output is correct |
40 |
Correct |
219 ms |
29292 KB |
Output is correct |
41 |
Correct |
213 ms |
29124 KB |
Output is correct |
42 |
Correct |
178 ms |
27244 KB |
Output is correct |
43 |
Correct |
239 ms |
31340 KB |
Output is correct |
44 |
Correct |
232 ms |
31468 KB |
Output is correct |
45 |
Correct |
127 ms |
22860 KB |
Output is correct |
46 |
Correct |
208 ms |
28652 KB |
Output is correct |
47 |
Correct |
31 ms |
13240 KB |
Output is correct |
48 |
Correct |
330 ms |
33748 KB |
Output is correct |
49 |
Correct |
322 ms |
33112 KB |
Output is correct |
50 |
Correct |
321 ms |
32980 KB |
Output is correct |
51 |
Correct |
313 ms |
32480 KB |
Output is correct |
52 |
Correct |
298 ms |
30904 KB |
Output is correct |
53 |
Correct |
221 ms |
26208 KB |
Output is correct |
54 |
Correct |
329 ms |
34132 KB |
Output is correct |
55 |
Correct |
332 ms |
34384 KB |
Output is correct |
56 |
Correct |
228 ms |
26064 KB |
Output is correct |
57 |
Correct |
310 ms |
31668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10496 KB |
Output is correct |
2 |
Correct |
7 ms |
10496 KB |
Output is correct |
3 |
Correct |
7 ms |
10496 KB |
Output is correct |
4 |
Correct |
7 ms |
10496 KB |
Output is correct |
5 |
Correct |
7 ms |
10624 KB |
Output is correct |
6 |
Correct |
9 ms |
10656 KB |
Output is correct |
7 |
Correct |
8 ms |
10624 KB |
Output is correct |
8 |
Correct |
7 ms |
10624 KB |
Output is correct |
9 |
Correct |
8 ms |
10624 KB |
Output is correct |
10 |
Correct |
170 ms |
26916 KB |
Output is correct |
11 |
Correct |
215 ms |
30188 KB |
Output is correct |
12 |
Correct |
211 ms |
29840 KB |
Output is correct |
13 |
Correct |
226 ms |
31044 KB |
Output is correct |
14 |
Correct |
142 ms |
23660 KB |
Output is correct |
15 |
Correct |
175 ms |
26860 KB |
Output is correct |
16 |
Correct |
316 ms |
32376 KB |
Output is correct |
17 |
Correct |
309 ms |
31900 KB |
Output is correct |
18 |
Correct |
330 ms |
33272 KB |
Output is correct |
19 |
Correct |
232 ms |
25552 KB |
Output is correct |
20 |
Correct |
208 ms |
24080 KB |
Output is correct |
21 |
Correct |
209 ms |
24532 KB |
Output is correct |
22 |
Correct |
207 ms |
24448 KB |
Output is correct |
23 |
Correct |
203 ms |
24404 KB |
Output is correct |
24 |
Correct |
212 ms |
24484 KB |
Output is correct |
25 |
Correct |
198 ms |
24200 KB |
Output is correct |
26 |
Correct |
204 ms |
24296 KB |
Output is correct |
27 |
Correct |
200 ms |
24104 KB |
Output is correct |
28 |
Correct |
7 ms |
10624 KB |
Output is correct |
29 |
Correct |
9 ms |
10624 KB |
Output is correct |
30 |
Correct |
8 ms |
10624 KB |
Output is correct |
31 |
Correct |
7 ms |
10624 KB |
Output is correct |
32 |
Correct |
8 ms |
10624 KB |
Output is correct |
33 |
Correct |
8 ms |
10624 KB |
Output is correct |
34 |
Correct |
7 ms |
10624 KB |
Output is correct |
35 |
Correct |
8 ms |
10624 KB |
Output is correct |
36 |
Correct |
8 ms |
10624 KB |
Output is correct |
37 |
Correct |
22 ms |
12864 KB |
Output is correct |
38 |
Correct |
236 ms |
30828 KB |
Output is correct |
39 |
Correct |
226 ms |
30828 KB |
Output is correct |
40 |
Correct |
219 ms |
30188 KB |
Output is correct |
41 |
Correct |
219 ms |
29292 KB |
Output is correct |
42 |
Correct |
213 ms |
29124 KB |
Output is correct |
43 |
Correct |
178 ms |
27244 KB |
Output is correct |
44 |
Correct |
239 ms |
31340 KB |
Output is correct |
45 |
Correct |
232 ms |
31468 KB |
Output is correct |
46 |
Correct |
127 ms |
22860 KB |
Output is correct |
47 |
Correct |
208 ms |
28652 KB |
Output is correct |
48 |
Correct |
31 ms |
13240 KB |
Output is correct |
49 |
Correct |
330 ms |
33748 KB |
Output is correct |
50 |
Correct |
322 ms |
33112 KB |
Output is correct |
51 |
Correct |
321 ms |
32980 KB |
Output is correct |
52 |
Correct |
313 ms |
32480 KB |
Output is correct |
53 |
Correct |
298 ms |
30904 KB |
Output is correct |
54 |
Correct |
221 ms |
26208 KB |
Output is correct |
55 |
Correct |
329 ms |
34132 KB |
Output is correct |
56 |
Correct |
332 ms |
34384 KB |
Output is correct |
57 |
Correct |
228 ms |
26064 KB |
Output is correct |
58 |
Correct |
310 ms |
31668 KB |
Output is correct |
59 |
Correct |
95 ms |
17080 KB |
Output is correct |
60 |
Correct |
313 ms |
33644 KB |
Output is correct |
61 |
Correct |
315 ms |
33332 KB |
Output is correct |
62 |
Correct |
334 ms |
34384 KB |
Output is correct |
63 |
Correct |
239 ms |
26836 KB |
Output is correct |
64 |
Correct |
8 ms |
10624 KB |
Output is correct |
65 |
Correct |
9 ms |
10624 KB |
Output is correct |
66 |
Correct |
7 ms |
10624 KB |
Output is correct |
67 |
Correct |
8 ms |
10624 KB |
Output is correct |
68 |
Correct |
7 ms |
10624 KB |
Output is correct |
69 |
Correct |
8 ms |
10752 KB |
Output is correct |
70 |
Correct |
8 ms |
10624 KB |
Output is correct |
71 |
Correct |
8 ms |
10752 KB |
Output is correct |
72 |
Correct |
7 ms |
10624 KB |
Output is correct |
73 |
Correct |
8 ms |
10624 KB |
Output is correct |
74 |
Correct |
176 ms |
23916 KB |
Output is correct |
75 |
Correct |
221 ms |
30700 KB |
Output is correct |
76 |
Correct |
196 ms |
27116 KB |
Output is correct |
77 |
Correct |
168 ms |
24300 KB |
Output is correct |
78 |
Correct |
95 ms |
16656 KB |
Output is correct |
79 |
Correct |
86 ms |
15548 KB |
Output is correct |
80 |
Correct |
140 ms |
21484 KB |
Output is correct |
81 |
Correct |
267 ms |
32000 KB |
Output is correct |
82 |
Correct |
249 ms |
27748 KB |
Output is correct |
83 |
Correct |
313 ms |
34788 KB |
Output is correct |
84 |
Correct |
134 ms |
23148 KB |
Output is correct |
85 |
Correct |
224 ms |
26856 KB |
Output is correct |
86 |
Correct |
76 ms |
15928 KB |
Output is correct |
87 |
Correct |
330 ms |
32628 KB |
Output is correct |
88 |
Correct |
316 ms |
32852 KB |
Output is correct |
89 |
Correct |
260 ms |
26200 KB |
Output is correct |
90 |
Correct |
187 ms |
18752 KB |
Output is correct |
91 |
Correct |
185 ms |
19468 KB |
Output is correct |
92 |
Correct |
229 ms |
24268 KB |
Output is correct |
93 |
Correct |
357 ms |
33836 KB |
Output is correct |
94 |
Correct |
350 ms |
30668 KB |
Output is correct |
95 |
Correct |
428 ms |
36872 KB |
Output is correct |
96 |
Correct |
234 ms |
26068 KB |
Output is correct |
97 |
Correct |
299 ms |
28712 KB |
Output is correct |