#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], b[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;
b[u][i]=~anc[u][i-1]?max(b[u][i-1], b[anc[u][i-1]][i-1]):0;
}
for(auto v : adj[u]) {
if(v[1]^p) {
b[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(b[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({b[x][i], b[y][i], r});
x=anc[x][i];
y=anc[y][i];
}
}
return max({b[x][0], b[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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
5 ms |
5248 KB |
Output is correct |
6 |
Correct |
5 ms |
5248 KB |
Output is correct |
7 |
Correct |
4 ms |
5248 KB |
Output is correct |
8 |
Correct |
4 ms |
5248 KB |
Output is correct |
9 |
Correct |
159 ms |
25196 KB |
Output is correct |
10 |
Correct |
191 ms |
30444 KB |
Output is correct |
11 |
Correct |
197 ms |
29676 KB |
Output is correct |
12 |
Correct |
203 ms |
31340 KB |
Output is correct |
13 |
Correct |
190 ms |
32420 KB |
Output is correct |
14 |
Correct |
174 ms |
24944 KB |
Output is correct |
15 |
Correct |
478 ms |
31964 KB |
Output is correct |
16 |
Correct |
461 ms |
30444 KB |
Output is correct |
17 |
Correct |
454 ms |
33900 KB |
Output is correct |
18 |
Correct |
448 ms |
33132 KB |
Output is correct |
19 |
Correct |
120 ms |
12668 KB |
Output is correct |
20 |
Correct |
467 ms |
32128 KB |
Output is correct |
21 |
Correct |
472 ms |
30756 KB |
Output is correct |
22 |
Correct |
491 ms |
33080 KB |
Output is correct |
23 |
Correct |
460 ms |
33456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
259 ms |
30644 KB |
Output is correct |
4 |
Correct |
259 ms |
31676 KB |
Output is correct |
5 |
Correct |
275 ms |
31232 KB |
Output is correct |
6 |
Correct |
272 ms |
31552 KB |
Output is correct |
7 |
Correct |
262 ms |
31464 KB |
Output is correct |
8 |
Correct |
261 ms |
30668 KB |
Output is correct |
9 |
Correct |
259 ms |
31216 KB |
Output is correct |
10 |
Correct |
281 ms |
30308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
5 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5248 KB |
Output is correct |
8 |
Correct |
4 ms |
5248 KB |
Output is correct |
9 |
Correct |
4 ms |
5248 KB |
Output is correct |
10 |
Correct |
4 ms |
5248 KB |
Output is correct |
11 |
Correct |
5 ms |
5248 KB |
Output is correct |
12 |
Correct |
4 ms |
5248 KB |
Output is correct |
13 |
Correct |
5 ms |
5248 KB |
Output is correct |
14 |
Correct |
4 ms |
5248 KB |
Output is correct |
15 |
Correct |
5 ms |
5248 KB |
Output is correct |
16 |
Correct |
4 ms |
5248 KB |
Output is correct |
17 |
Correct |
5 ms |
5248 KB |
Output is correct |
18 |
Correct |
4 ms |
5248 KB |
Output is correct |
19 |
Correct |
4 ms |
5248 KB |
Output is correct |
20 |
Correct |
5 ms |
5248 KB |
Output is correct |
21 |
Correct |
4 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 |
5248 KB |
Output is correct |
25 |
Correct |
5 ms |
5248 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 |
5248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
5 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5248 KB |
Output is correct |
8 |
Correct |
4 ms |
5248 KB |
Output is correct |
9 |
Correct |
4 ms |
5248 KB |
Output is correct |
10 |
Correct |
159 ms |
25196 KB |
Output is correct |
11 |
Correct |
191 ms |
30444 KB |
Output is correct |
12 |
Correct |
197 ms |
29676 KB |
Output is correct |
13 |
Correct |
203 ms |
31340 KB |
Output is correct |
14 |
Correct |
190 ms |
32420 KB |
Output is correct |
15 |
Correct |
4 ms |
5248 KB |
Output is correct |
16 |
Correct |
5 ms |
5248 KB |
Output is correct |
17 |
Correct |
4 ms |
5248 KB |
Output is correct |
18 |
Correct |
5 ms |
5248 KB |
Output is correct |
19 |
Correct |
4 ms |
5248 KB |
Output is correct |
20 |
Correct |
5 ms |
5248 KB |
Output is correct |
21 |
Correct |
4 ms |
5248 KB |
Output is correct |
22 |
Correct |
5 ms |
5248 KB |
Output is correct |
23 |
Correct |
4 ms |
5248 KB |
Output is correct |
24 |
Correct |
18 ms |
8148 KB |
Output is correct |
25 |
Correct |
211 ms |
31084 KB |
Output is correct |
26 |
Correct |
210 ms |
29548 KB |
Output is correct |
27 |
Correct |
194 ms |
28296 KB |
Output is correct |
28 |
Correct |
197 ms |
27880 KB |
Output is correct |
29 |
Correct |
186 ms |
27500 KB |
Output is correct |
30 |
Correct |
164 ms |
25708 KB |
Output is correct |
31 |
Correct |
212 ms |
29932 KB |
Output is correct |
32 |
Correct |
219 ms |
30572 KB |
Output is correct |
33 |
Correct |
174 ms |
31340 KB |
Output is correct |
34 |
Correct |
187 ms |
28372 KB |
Output is correct |
35 |
Correct |
4 ms |
5248 KB |
Output is correct |
36 |
Correct |
5 ms |
5248 KB |
Output is correct |
37 |
Correct |
4 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 |
5248 KB |
Output is correct |
41 |
Correct |
5 ms |
5248 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 |
5248 KB |
Output is correct |
45 |
Correct |
181 ms |
25700 KB |
Output is correct |
46 |
Correct |
204 ms |
28908 KB |
Output is correct |
47 |
Correct |
195 ms |
27756 KB |
Output is correct |
48 |
Correct |
172 ms |
27884 KB |
Output is correct |
49 |
Correct |
91 ms |
12012 KB |
Output is correct |
50 |
Correct |
80 ms |
10732 KB |
Output is correct |
51 |
Correct |
162 ms |
22148 KB |
Output is correct |
52 |
Correct |
242 ms |
31076 KB |
Output is correct |
53 |
Correct |
238 ms |
31716 KB |
Output is correct |
54 |
Correct |
278 ms |
33528 KB |
Output is correct |
55 |
Correct |
176 ms |
32108 KB |
Output is correct |
56 |
Correct |
239 ms |
30724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4992 KB |
Output is correct |
2 |
Correct |
4 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
4 ms |
5120 KB |
Output is correct |
5 |
Correct |
5 ms |
5248 KB |
Output is correct |
6 |
Correct |
5 ms |
5248 KB |
Output is correct |
7 |
Correct |
4 ms |
5248 KB |
Output is correct |
8 |
Correct |
4 ms |
5248 KB |
Output is correct |
9 |
Correct |
159 ms |
25196 KB |
Output is correct |
10 |
Correct |
191 ms |
30444 KB |
Output is correct |
11 |
Correct |
197 ms |
29676 KB |
Output is correct |
12 |
Correct |
203 ms |
31340 KB |
Output is correct |
13 |
Correct |
190 ms |
32420 KB |
Output is correct |
14 |
Correct |
174 ms |
24944 KB |
Output is correct |
15 |
Correct |
478 ms |
31964 KB |
Output is correct |
16 |
Correct |
461 ms |
30444 KB |
Output is correct |
17 |
Correct |
454 ms |
33900 KB |
Output is correct |
18 |
Correct |
448 ms |
33132 KB |
Output is correct |
19 |
Correct |
259 ms |
30644 KB |
Output is correct |
20 |
Correct |
259 ms |
31676 KB |
Output is correct |
21 |
Correct |
275 ms |
31232 KB |
Output is correct |
22 |
Correct |
272 ms |
31552 KB |
Output is correct |
23 |
Correct |
262 ms |
31464 KB |
Output is correct |
24 |
Correct |
261 ms |
30668 KB |
Output is correct |
25 |
Correct |
259 ms |
31216 KB |
Output is correct |
26 |
Correct |
281 ms |
30308 KB |
Output is correct |
27 |
Correct |
4 ms |
5248 KB |
Output is correct |
28 |
Correct |
5 ms |
5248 KB |
Output is correct |
29 |
Correct |
4 ms |
5248 KB |
Output is correct |
30 |
Correct |
5 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 |
4 ms |
5248 KB |
Output is correct |
34 |
Correct |
5 ms |
5248 KB |
Output is correct |
35 |
Correct |
4 ms |
5248 KB |
Output is correct |
36 |
Correct |
18 ms |
8148 KB |
Output is correct |
37 |
Correct |
211 ms |
31084 KB |
Output is correct |
38 |
Correct |
210 ms |
29548 KB |
Output is correct |
39 |
Correct |
194 ms |
28296 KB |
Output is correct |
40 |
Correct |
197 ms |
27880 KB |
Output is correct |
41 |
Correct |
186 ms |
27500 KB |
Output is correct |
42 |
Correct |
164 ms |
25708 KB |
Output is correct |
43 |
Correct |
212 ms |
29932 KB |
Output is correct |
44 |
Correct |
219 ms |
30572 KB |
Output is correct |
45 |
Correct |
174 ms |
31340 KB |
Output is correct |
46 |
Correct |
187 ms |
28372 KB |
Output is correct |
47 |
Correct |
29 ms |
8200 KB |
Output is correct |
48 |
Correct |
516 ms |
31464 KB |
Output is correct |
49 |
Correct |
487 ms |
30572 KB |
Output is correct |
50 |
Correct |
460 ms |
30060 KB |
Output is correct |
51 |
Correct |
476 ms |
29548 KB |
Output is correct |
52 |
Correct |
427 ms |
28012 KB |
Output is correct |
53 |
Correct |
309 ms |
23248 KB |
Output is correct |
54 |
Correct |
545 ms |
31544 KB |
Output is correct |
55 |
Correct |
523 ms |
31852 KB |
Output is correct |
56 |
Correct |
440 ms |
33260 KB |
Output is correct |
57 |
Correct |
402 ms |
30300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
4 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
4 ms |
5120 KB |
Output is correct |
6 |
Correct |
5 ms |
5248 KB |
Output is correct |
7 |
Correct |
5 ms |
5248 KB |
Output is correct |
8 |
Correct |
4 ms |
5248 KB |
Output is correct |
9 |
Correct |
4 ms |
5248 KB |
Output is correct |
10 |
Correct |
159 ms |
25196 KB |
Output is correct |
11 |
Correct |
191 ms |
30444 KB |
Output is correct |
12 |
Correct |
197 ms |
29676 KB |
Output is correct |
13 |
Correct |
203 ms |
31340 KB |
Output is correct |
14 |
Correct |
190 ms |
32420 KB |
Output is correct |
15 |
Correct |
174 ms |
24944 KB |
Output is correct |
16 |
Correct |
478 ms |
31964 KB |
Output is correct |
17 |
Correct |
461 ms |
30444 KB |
Output is correct |
18 |
Correct |
454 ms |
33900 KB |
Output is correct |
19 |
Correct |
448 ms |
33132 KB |
Output is correct |
20 |
Correct |
259 ms |
30644 KB |
Output is correct |
21 |
Correct |
259 ms |
31676 KB |
Output is correct |
22 |
Correct |
275 ms |
31232 KB |
Output is correct |
23 |
Correct |
272 ms |
31552 KB |
Output is correct |
24 |
Correct |
262 ms |
31464 KB |
Output is correct |
25 |
Correct |
261 ms |
30668 KB |
Output is correct |
26 |
Correct |
259 ms |
31216 KB |
Output is correct |
27 |
Correct |
281 ms |
30308 KB |
Output is correct |
28 |
Correct |
4 ms |
5248 KB |
Output is correct |
29 |
Correct |
5 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 |
4 ms |
5248 KB |
Output is correct |
33 |
Correct |
5 ms |
5248 KB |
Output is correct |
34 |
Correct |
4 ms |
5248 KB |
Output is correct |
35 |
Correct |
5 ms |
5248 KB |
Output is correct |
36 |
Correct |
4 ms |
5248 KB |
Output is correct |
37 |
Correct |
18 ms |
8148 KB |
Output is correct |
38 |
Correct |
211 ms |
31084 KB |
Output is correct |
39 |
Correct |
210 ms |
29548 KB |
Output is correct |
40 |
Correct |
194 ms |
28296 KB |
Output is correct |
41 |
Correct |
197 ms |
27880 KB |
Output is correct |
42 |
Correct |
186 ms |
27500 KB |
Output is correct |
43 |
Correct |
164 ms |
25708 KB |
Output is correct |
44 |
Correct |
212 ms |
29932 KB |
Output is correct |
45 |
Correct |
219 ms |
30572 KB |
Output is correct |
46 |
Correct |
174 ms |
31340 KB |
Output is correct |
47 |
Correct |
187 ms |
28372 KB |
Output is correct |
48 |
Correct |
29 ms |
8200 KB |
Output is correct |
49 |
Correct |
516 ms |
31464 KB |
Output is correct |
50 |
Correct |
487 ms |
30572 KB |
Output is correct |
51 |
Correct |
460 ms |
30060 KB |
Output is correct |
52 |
Correct |
476 ms |
29548 KB |
Output is correct |
53 |
Correct |
427 ms |
28012 KB |
Output is correct |
54 |
Correct |
309 ms |
23248 KB |
Output is correct |
55 |
Correct |
545 ms |
31544 KB |
Output is correct |
56 |
Correct |
523 ms |
31852 KB |
Output is correct |
57 |
Correct |
440 ms |
33260 KB |
Output is correct |
58 |
Correct |
402 ms |
30300 KB |
Output is correct |
59 |
Correct |
120 ms |
12668 KB |
Output is correct |
60 |
Correct |
467 ms |
32128 KB |
Output is correct |
61 |
Correct |
472 ms |
30756 KB |
Output is correct |
62 |
Correct |
491 ms |
33080 KB |
Output is correct |
63 |
Correct |
460 ms |
33456 KB |
Output is correct |
64 |
Correct |
4 ms |
5248 KB |
Output is correct |
65 |
Correct |
5 ms |
5248 KB |
Output is correct |
66 |
Correct |
4 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 |
5248 KB |
Output is correct |
70 |
Correct |
5 ms |
5248 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 |
5248 KB |
Output is correct |
74 |
Correct |
181 ms |
25700 KB |
Output is correct |
75 |
Correct |
204 ms |
28908 KB |
Output is correct |
76 |
Correct |
195 ms |
27756 KB |
Output is correct |
77 |
Correct |
172 ms |
27884 KB |
Output is correct |
78 |
Correct |
91 ms |
12012 KB |
Output is correct |
79 |
Correct |
80 ms |
10732 KB |
Output is correct |
80 |
Correct |
162 ms |
22148 KB |
Output is correct |
81 |
Correct |
242 ms |
31076 KB |
Output is correct |
82 |
Correct |
238 ms |
31716 KB |
Output is correct |
83 |
Correct |
278 ms |
33528 KB |
Output is correct |
84 |
Correct |
176 ms |
32108 KB |
Output is correct |
85 |
Correct |
239 ms |
30724 KB |
Output is correct |
86 |
Correct |
94 ms |
13340 KB |
Output is correct |
87 |
Correct |
508 ms |
30316 KB |
Output is correct |
88 |
Correct |
507 ms |
30424 KB |
Output is correct |
89 |
Correct |
352 ms |
28140 KB |
Output is correct |
90 |
Correct |
199 ms |
13676 KB |
Output is correct |
91 |
Correct |
218 ms |
14152 KB |
Output is correct |
92 |
Correct |
323 ms |
23528 KB |
Output is correct |
93 |
Correct |
540 ms |
32740 KB |
Output is correct |
94 |
Correct |
439 ms |
33000 KB |
Output is correct |
95 |
Correct |
572 ms |
35048 KB |
Output is correct |
96 |
Correct |
457 ms |
32108 KB |
Output is correct |
97 |
Correct |
395 ms |
31016 KB |
Output is correct |