#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define ar array
const int mxN=1e5;
int a[mxN], r[mxN], d[mxN], anc[mxN][17], b1[mxN][17];
vector<ar<int, 2>> adj[mxN];
vector<int> adj2[mxN];
int find(int x) {
return x^r[x]?r[x]=find(r[x]):x;
}
void dfs2(int u, int w) {
a[u]=min(w, a[u]);
for(int v : adj2[u])
dfs2(v, w);
adj2[u].clear();
}
bool join(int x, int y, int w) {
if((x=find(x))==(y=find(y)))
return 0;
r[x]=y;
if(a[y]<=1e9)
dfs2(x, w);
if(a[x]<=1e9)
dfs2(y, w);
adj2[y].push_back(x);
return 1;
}
void dfs(int u=0, int p=-1) {
anc[u][0]=p;
for(int i=1; i<17; ++i) {
anc[u][i]=~anc[u][i-1]?anc[anc[u][i-1]][i-1]:-1;
b1[u][i]=~anc[u][i-1]?max(b1[u][i-1], b1[anc[u][i-1]][i-1]):0;
}
for(auto v : adj[u]) {
if(v[1]^p) {
b1[v[1]][0]=v[0];
d[v[1]]=d[u]+1;
dfs(v[1], u);
}
}
}
int qry(int x, int y) {
if(d[x]<d[y])
swap(x, y);
int r=0;
for(int i=16; ~i; --i) {
if(d[x]-(1<<i)>=d[y]) {
r=max(b1[x][i], r);
x=anc[x][i];
}
}
if(x==y)
return r;
for(int i=16; ~i; --i) {
if(anc[x][i]^anc[y][i]) {
r=max({b1[x][i], b1[y][i], r});
x=anc[x][i];
y=anc[y][i];
}
}
return max({b1[x][0], b1[y][0], r});
}
void init(int n, int m, vector<int> u, vector<int> v, vector<int> w) {
vector<ar<int, 3>> e;
for(int i=0; i<m; ++i)
e.push_back({w[i], u[i], v[i]});
sort(e.begin(), e.end());
memset(a, 0x3f, 4*n);
iota(r, r+n, 0);
for(auto f : e) {
if(join(f[1], f[2], f[0])) {
adj[f[1]].push_back({f[0], f[2]});
adj[f[2]].push_back({f[0], f[1]});
if(adj[f[1]].size()>2||adj[f[2]].size()>2)
dfs2(find(f[1]), f[0]);
} else
dfs2(find(f[1]), f[0]);
}
dfs();
}
int getMinimumFuelCapacity(int x, int y) {
int b=max(qry(x, y), a[x]);
return b>1e9?-1:b;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
6 ms |
5248 KB |
Output is correct |
6 |
Correct |
5 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5248 KB |
Output is correct |
8 |
Correct |
5 ms |
5376 KB |
Output is correct |
9 |
Correct |
153 ms |
25204 KB |
Output is correct |
10 |
Correct |
203 ms |
30700 KB |
Output is correct |
11 |
Correct |
191 ms |
29936 KB |
Output is correct |
12 |
Correct |
207 ms |
31596 KB |
Output is correct |
13 |
Correct |
180 ms |
32572 KB |
Output is correct |
14 |
Correct |
177 ms |
25072 KB |
Output is correct |
15 |
Correct |
479 ms |
32236 KB |
Output is correct |
16 |
Correct |
473 ms |
30700 KB |
Output is correct |
17 |
Correct |
449 ms |
34096 KB |
Output is correct |
18 |
Correct |
433 ms |
33256 KB |
Output is correct |
19 |
Correct |
120 ms |
12856 KB |
Output is correct |
20 |
Correct |
485 ms |
32092 KB |
Output is correct |
21 |
Correct |
480 ms |
30940 KB |
Output is correct |
22 |
Correct |
503 ms |
33336 KB |
Output is correct |
23 |
Correct |
468 ms |
33468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
256 ms |
31048 KB |
Output is correct |
4 |
Correct |
262 ms |
31932 KB |
Output is correct |
5 |
Correct |
272 ms |
31512 KB |
Output is correct |
6 |
Correct |
259 ms |
31900 KB |
Output is correct |
7 |
Correct |
268 ms |
31852 KB |
Output is correct |
8 |
Correct |
261 ms |
30664 KB |
Output is correct |
9 |
Correct |
260 ms |
31532 KB |
Output is correct |
10 |
Correct |
257 ms |
30532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5248 KB |
Output is correct |
8 |
Correct |
5 ms |
5248 KB |
Output is correct |
9 |
Correct |
5 ms |
5376 KB |
Output is correct |
10 |
Correct |
5 ms |
5248 KB |
Output is correct |
11 |
Correct |
4 ms |
5248 KB |
Output is correct |
12 |
Correct |
4 ms |
5248 KB |
Output is correct |
13 |
Correct |
4 ms |
5248 KB |
Output is correct |
14 |
Correct |
5 ms |
5248 KB |
Output is correct |
15 |
Correct |
6 ms |
5248 KB |
Output is correct |
16 |
Correct |
5 ms |
5248 KB |
Output is correct |
17 |
Correct |
5 ms |
5376 KB |
Output is correct |
18 |
Correct |
5 ms |
5248 KB |
Output is correct |
19 |
Correct |
6 ms |
5248 KB |
Output is correct |
20 |
Correct |
4 ms |
5248 KB |
Output is correct |
21 |
Correct |
5 ms |
5248 KB |
Output is correct |
22 |
Correct |
5 ms |
5120 KB |
Output is correct |
23 |
Correct |
5 ms |
5248 KB |
Output is correct |
24 |
Correct |
5 ms |
5376 KB |
Output is correct |
25 |
Correct |
5 ms |
5376 KB |
Output is correct |
26 |
Correct |
5 ms |
5376 KB |
Output is correct |
27 |
Correct |
5 ms |
5248 KB |
Output is correct |
28 |
Correct |
5 ms |
5376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5248 KB |
Output is correct |
8 |
Correct |
5 ms |
5248 KB |
Output is correct |
9 |
Correct |
5 ms |
5376 KB |
Output is correct |
10 |
Correct |
153 ms |
25204 KB |
Output is correct |
11 |
Correct |
203 ms |
30700 KB |
Output is correct |
12 |
Correct |
191 ms |
29936 KB |
Output is correct |
13 |
Correct |
207 ms |
31596 KB |
Output is correct |
14 |
Correct |
180 ms |
32572 KB |
Output is correct |
15 |
Correct |
5 ms |
5248 KB |
Output is correct |
16 |
Correct |
4 ms |
5248 KB |
Output is correct |
17 |
Correct |
4 ms |
5248 KB |
Output is correct |
18 |
Correct |
4 ms |
5248 KB |
Output is correct |
19 |
Correct |
5 ms |
5248 KB |
Output is correct |
20 |
Correct |
6 ms |
5248 KB |
Output is correct |
21 |
Correct |
5 ms |
5248 KB |
Output is correct |
22 |
Correct |
5 ms |
5376 KB |
Output is correct |
23 |
Correct |
5 ms |
5248 KB |
Output is correct |
24 |
Correct |
19 ms |
8256 KB |
Output is correct |
25 |
Correct |
213 ms |
31212 KB |
Output is correct |
26 |
Correct |
216 ms |
29548 KB |
Output is correct |
27 |
Correct |
215 ms |
28396 KB |
Output is correct |
28 |
Correct |
219 ms |
27884 KB |
Output is correct |
29 |
Correct |
202 ms |
27500 KB |
Output is correct |
30 |
Correct |
177 ms |
25836 KB |
Output is correct |
31 |
Correct |
234 ms |
30060 KB |
Output is correct |
32 |
Correct |
234 ms |
30704 KB |
Output is correct |
33 |
Correct |
186 ms |
31468 KB |
Output is correct |
34 |
Correct |
189 ms |
28396 KB |
Output is correct |
35 |
Correct |
6 ms |
5248 KB |
Output is correct |
36 |
Correct |
4 ms |
5248 KB |
Output is correct |
37 |
Correct |
5 ms |
5248 KB |
Output is correct |
38 |
Correct |
5 ms |
5120 KB |
Output is correct |
39 |
Correct |
5 ms |
5248 KB |
Output is correct |
40 |
Correct |
5 ms |
5376 KB |
Output is correct |
41 |
Correct |
5 ms |
5376 KB |
Output is correct |
42 |
Correct |
5 ms |
5376 KB |
Output is correct |
43 |
Correct |
5 ms |
5248 KB |
Output is correct |
44 |
Correct |
5 ms |
5376 KB |
Output is correct |
45 |
Correct |
185 ms |
25828 KB |
Output is correct |
46 |
Correct |
214 ms |
28908 KB |
Output is correct |
47 |
Correct |
204 ms |
27884 KB |
Output is correct |
48 |
Correct |
180 ms |
28044 KB |
Output is correct |
49 |
Correct |
92 ms |
12144 KB |
Output is correct |
50 |
Correct |
79 ms |
10988 KB |
Output is correct |
51 |
Correct |
153 ms |
22252 KB |
Output is correct |
52 |
Correct |
241 ms |
31200 KB |
Output is correct |
53 |
Correct |
242 ms |
31776 KB |
Output is correct |
54 |
Correct |
284 ms |
33640 KB |
Output is correct |
55 |
Correct |
188 ms |
32300 KB |
Output is correct |
56 |
Correct |
241 ms |
30948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
6 ms |
5248 KB |
Output is correct |
6 |
Correct |
5 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5248 KB |
Output is correct |
8 |
Correct |
5 ms |
5376 KB |
Output is correct |
9 |
Correct |
153 ms |
25204 KB |
Output is correct |
10 |
Correct |
203 ms |
30700 KB |
Output is correct |
11 |
Correct |
191 ms |
29936 KB |
Output is correct |
12 |
Correct |
207 ms |
31596 KB |
Output is correct |
13 |
Correct |
180 ms |
32572 KB |
Output is correct |
14 |
Correct |
177 ms |
25072 KB |
Output is correct |
15 |
Correct |
479 ms |
32236 KB |
Output is correct |
16 |
Correct |
473 ms |
30700 KB |
Output is correct |
17 |
Correct |
449 ms |
34096 KB |
Output is correct |
18 |
Correct |
433 ms |
33256 KB |
Output is correct |
19 |
Correct |
256 ms |
31048 KB |
Output is correct |
20 |
Correct |
262 ms |
31932 KB |
Output is correct |
21 |
Correct |
272 ms |
31512 KB |
Output is correct |
22 |
Correct |
259 ms |
31900 KB |
Output is correct |
23 |
Correct |
268 ms |
31852 KB |
Output is correct |
24 |
Correct |
261 ms |
30664 KB |
Output is correct |
25 |
Correct |
260 ms |
31532 KB |
Output is correct |
26 |
Correct |
257 ms |
30532 KB |
Output is correct |
27 |
Correct |
5 ms |
5248 KB |
Output is correct |
28 |
Correct |
4 ms |
5248 KB |
Output is correct |
29 |
Correct |
4 ms |
5248 KB |
Output is correct |
30 |
Correct |
4 ms |
5248 KB |
Output is correct |
31 |
Correct |
5 ms |
5248 KB |
Output is correct |
32 |
Correct |
6 ms |
5248 KB |
Output is correct |
33 |
Correct |
5 ms |
5248 KB |
Output is correct |
34 |
Correct |
5 ms |
5376 KB |
Output is correct |
35 |
Correct |
5 ms |
5248 KB |
Output is correct |
36 |
Correct |
19 ms |
8256 KB |
Output is correct |
37 |
Correct |
213 ms |
31212 KB |
Output is correct |
38 |
Correct |
216 ms |
29548 KB |
Output is correct |
39 |
Correct |
215 ms |
28396 KB |
Output is correct |
40 |
Correct |
219 ms |
27884 KB |
Output is correct |
41 |
Correct |
202 ms |
27500 KB |
Output is correct |
42 |
Correct |
177 ms |
25836 KB |
Output is correct |
43 |
Correct |
234 ms |
30060 KB |
Output is correct |
44 |
Correct |
234 ms |
30704 KB |
Output is correct |
45 |
Correct |
186 ms |
31468 KB |
Output is correct |
46 |
Correct |
189 ms |
28396 KB |
Output is correct |
47 |
Correct |
30 ms |
8228 KB |
Output is correct |
48 |
Correct |
489 ms |
31724 KB |
Output is correct |
49 |
Correct |
524 ms |
30700 KB |
Output is correct |
50 |
Correct |
482 ms |
30136 KB |
Output is correct |
51 |
Correct |
465 ms |
29676 KB |
Output is correct |
52 |
Correct |
430 ms |
28140 KB |
Output is correct |
53 |
Correct |
294 ms |
23504 KB |
Output is correct |
54 |
Correct |
527 ms |
31676 KB |
Output is correct |
55 |
Correct |
476 ms |
31976 KB |
Output is correct |
56 |
Correct |
429 ms |
33592 KB |
Output is correct |
57 |
Correct |
376 ms |
30392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
5 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5248 KB |
Output is correct |
8 |
Correct |
5 ms |
5248 KB |
Output is correct |
9 |
Correct |
5 ms |
5376 KB |
Output is correct |
10 |
Correct |
153 ms |
25204 KB |
Output is correct |
11 |
Correct |
203 ms |
30700 KB |
Output is correct |
12 |
Correct |
191 ms |
29936 KB |
Output is correct |
13 |
Correct |
207 ms |
31596 KB |
Output is correct |
14 |
Correct |
180 ms |
32572 KB |
Output is correct |
15 |
Correct |
177 ms |
25072 KB |
Output is correct |
16 |
Correct |
479 ms |
32236 KB |
Output is correct |
17 |
Correct |
473 ms |
30700 KB |
Output is correct |
18 |
Correct |
449 ms |
34096 KB |
Output is correct |
19 |
Correct |
433 ms |
33256 KB |
Output is correct |
20 |
Correct |
256 ms |
31048 KB |
Output is correct |
21 |
Correct |
262 ms |
31932 KB |
Output is correct |
22 |
Correct |
272 ms |
31512 KB |
Output is correct |
23 |
Correct |
259 ms |
31900 KB |
Output is correct |
24 |
Correct |
268 ms |
31852 KB |
Output is correct |
25 |
Correct |
261 ms |
30664 KB |
Output is correct |
26 |
Correct |
260 ms |
31532 KB |
Output is correct |
27 |
Correct |
257 ms |
30532 KB |
Output is correct |
28 |
Correct |
5 ms |
5248 KB |
Output is correct |
29 |
Correct |
4 ms |
5248 KB |
Output is correct |
30 |
Correct |
4 ms |
5248 KB |
Output is correct |
31 |
Correct |
4 ms |
5248 KB |
Output is correct |
32 |
Correct |
5 ms |
5248 KB |
Output is correct |
33 |
Correct |
6 ms |
5248 KB |
Output is correct |
34 |
Correct |
5 ms |
5248 KB |
Output is correct |
35 |
Correct |
5 ms |
5376 KB |
Output is correct |
36 |
Correct |
5 ms |
5248 KB |
Output is correct |
37 |
Correct |
19 ms |
8256 KB |
Output is correct |
38 |
Correct |
213 ms |
31212 KB |
Output is correct |
39 |
Correct |
216 ms |
29548 KB |
Output is correct |
40 |
Correct |
215 ms |
28396 KB |
Output is correct |
41 |
Correct |
219 ms |
27884 KB |
Output is correct |
42 |
Correct |
202 ms |
27500 KB |
Output is correct |
43 |
Correct |
177 ms |
25836 KB |
Output is correct |
44 |
Correct |
234 ms |
30060 KB |
Output is correct |
45 |
Correct |
234 ms |
30704 KB |
Output is correct |
46 |
Correct |
186 ms |
31468 KB |
Output is correct |
47 |
Correct |
189 ms |
28396 KB |
Output is correct |
48 |
Correct |
30 ms |
8228 KB |
Output is correct |
49 |
Correct |
489 ms |
31724 KB |
Output is correct |
50 |
Correct |
524 ms |
30700 KB |
Output is correct |
51 |
Correct |
482 ms |
30136 KB |
Output is correct |
52 |
Correct |
465 ms |
29676 KB |
Output is correct |
53 |
Correct |
430 ms |
28140 KB |
Output is correct |
54 |
Correct |
294 ms |
23504 KB |
Output is correct |
55 |
Correct |
527 ms |
31676 KB |
Output is correct |
56 |
Correct |
476 ms |
31976 KB |
Output is correct |
57 |
Correct |
429 ms |
33592 KB |
Output is correct |
58 |
Correct |
376 ms |
30392 KB |
Output is correct |
59 |
Correct |
120 ms |
12856 KB |
Output is correct |
60 |
Correct |
485 ms |
32092 KB |
Output is correct |
61 |
Correct |
480 ms |
30940 KB |
Output is correct |
62 |
Correct |
503 ms |
33336 KB |
Output is correct |
63 |
Correct |
468 ms |
33468 KB |
Output is correct |
64 |
Correct |
6 ms |
5248 KB |
Output is correct |
65 |
Correct |
4 ms |
5248 KB |
Output is correct |
66 |
Correct |
5 ms |
5248 KB |
Output is correct |
67 |
Correct |
5 ms |
5120 KB |
Output is correct |
68 |
Correct |
5 ms |
5248 KB |
Output is correct |
69 |
Correct |
5 ms |
5376 KB |
Output is correct |
70 |
Correct |
5 ms |
5376 KB |
Output is correct |
71 |
Correct |
5 ms |
5376 KB |
Output is correct |
72 |
Correct |
5 ms |
5248 KB |
Output is correct |
73 |
Correct |
5 ms |
5376 KB |
Output is correct |
74 |
Correct |
185 ms |
25828 KB |
Output is correct |
75 |
Correct |
214 ms |
28908 KB |
Output is correct |
76 |
Correct |
204 ms |
27884 KB |
Output is correct |
77 |
Correct |
180 ms |
28044 KB |
Output is correct |
78 |
Correct |
92 ms |
12144 KB |
Output is correct |
79 |
Correct |
79 ms |
10988 KB |
Output is correct |
80 |
Correct |
153 ms |
22252 KB |
Output is correct |
81 |
Correct |
241 ms |
31200 KB |
Output is correct |
82 |
Correct |
242 ms |
31776 KB |
Output is correct |
83 |
Correct |
284 ms |
33640 KB |
Output is correct |
84 |
Correct |
188 ms |
32300 KB |
Output is correct |
85 |
Correct |
241 ms |
30948 KB |
Output is correct |
86 |
Correct |
94 ms |
13424 KB |
Output is correct |
87 |
Correct |
512 ms |
30476 KB |
Output is correct |
88 |
Correct |
504 ms |
30572 KB |
Output is correct |
89 |
Correct |
345 ms |
28396 KB |
Output is correct |
90 |
Correct |
198 ms |
13932 KB |
Output is correct |
91 |
Correct |
223 ms |
14440 KB |
Output is correct |
92 |
Correct |
313 ms |
23788 KB |
Output is correct |
93 |
Correct |
521 ms |
33000 KB |
Output is correct |
94 |
Correct |
434 ms |
33200 KB |
Output is correct |
95 |
Correct |
559 ms |
35048 KB |
Output is correct |
96 |
Correct |
483 ms |
32240 KB |
Output is correct |
97 |
Correct |
396 ms |
31188 KB |
Output is correct |