#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int maxn = 2e5+5;
int a[maxn],c[maxn],d[maxn],p[maxn];
int findpar(int u){
return (p[u]<0?u:findpar(p[u]));
}
void unions(int u,int v,int w,bool e){
u=findpar(u);v=findpar(v);
if(u==v) c[u]=min(c[u],w);
else{
if(p[u]>p[v]) swap(u,v);
p[u]+=p[v];p[v]=u;a[v]=w;
c[u]=min(c[u],max(w,e?0:c[v]));
}
}
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
for(int i=0;i<N;i++) p[i]=-1,a[i]=c[i]=inf;
vector<int> ord(M);
iota(ord.begin(),ord.end(),0);
sort(ord.begin(),ord.end(),[&](int x,int y){
return W[x]<W[y];
});
for(int i:ord){
d[U[i]]++;d[V[i]]++;
unions(U[i],V[i],W[i],(d[U[i]]>=3 || d[V[i]]>=3));
}
}
int getMinimumFuelCapacity(int u, int v) {
int w=-1;
while(u!=v){
if(a[u]<a[v]) w=a[u],u=p[u];
else w=a[v],v=p[v];
}
while(u>=0){
if(c[u]!=inf) return max(w,c[u]);
w=a[u];u=p[u];
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
28 ms |
6576 KB |
Output is correct |
10 |
Correct |
34 ms |
7248 KB |
Output is correct |
11 |
Correct |
43 ms |
7252 KB |
Output is correct |
12 |
Correct |
34 ms |
7768 KB |
Output is correct |
13 |
Correct |
33 ms |
7844 KB |
Output is correct |
14 |
Correct |
32 ms |
6996 KB |
Output is correct |
15 |
Correct |
92 ms |
10824 KB |
Output is correct |
16 |
Correct |
102 ms |
10656 KB |
Output is correct |
17 |
Correct |
100 ms |
11296 KB |
Output is correct |
18 |
Correct |
79 ms |
11092 KB |
Output is correct |
19 |
Correct |
52 ms |
8156 KB |
Output is correct |
20 |
Correct |
91 ms |
11604 KB |
Output is correct |
21 |
Correct |
97 ms |
11856 KB |
Output is correct |
22 |
Correct |
97 ms |
12180 KB |
Output is correct |
23 |
Correct |
84 ms |
12188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
76 ms |
11172 KB |
Output is correct |
4 |
Correct |
76 ms |
12084 KB |
Output is correct |
5 |
Correct |
91 ms |
12404 KB |
Output is correct |
6 |
Correct |
90 ms |
11932 KB |
Output is correct |
7 |
Correct |
76 ms |
12200 KB |
Output is correct |
8 |
Correct |
80 ms |
12176 KB |
Output is correct |
9 |
Correct |
77 ms |
12116 KB |
Output is correct |
10 |
Correct |
76 ms |
11956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2500 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2500 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
28 ms |
6576 KB |
Output is correct |
11 |
Correct |
34 ms |
7248 KB |
Output is correct |
12 |
Correct |
43 ms |
7252 KB |
Output is correct |
13 |
Correct |
34 ms |
7768 KB |
Output is correct |
14 |
Correct |
33 ms |
7844 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2500 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2500 KB |
Output is correct |
25 |
Correct |
1 ms |
2392 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2392 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
5 ms |
3164 KB |
Output is correct |
35 |
Correct |
34 ms |
7648 KB |
Output is correct |
36 |
Correct |
33 ms |
7508 KB |
Output is correct |
37 |
Correct |
33 ms |
7504 KB |
Output is correct |
38 |
Correct |
32 ms |
7504 KB |
Output is correct |
39 |
Correct |
34 ms |
7504 KB |
Output is correct |
40 |
Correct |
32 ms |
7128 KB |
Output is correct |
41 |
Correct |
33 ms |
7888 KB |
Output is correct |
42 |
Correct |
33 ms |
7516 KB |
Output is correct |
43 |
Correct |
32 ms |
7516 KB |
Output is correct |
44 |
Correct |
34 ms |
7772 KB |
Output is correct |
45 |
Correct |
51 ms |
10104 KB |
Output is correct |
46 |
Correct |
37 ms |
7504 KB |
Output is correct |
47 |
Correct |
32 ms |
7504 KB |
Output is correct |
48 |
Correct |
37 ms |
7876 KB |
Output is correct |
49 |
Correct |
52 ms |
9568 KB |
Output is correct |
50 |
Correct |
48 ms |
8016 KB |
Output is correct |
51 |
Correct |
50 ms |
9140 KB |
Output is correct |
52 |
Correct |
57 ms |
10832 KB |
Output is correct |
53 |
Correct |
72 ms |
11692 KB |
Output is correct |
54 |
Correct |
72 ms |
12480 KB |
Output is correct |
55 |
Correct |
32 ms |
7516 KB |
Output is correct |
56 |
Correct |
62 ms |
11560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
28 ms |
6576 KB |
Output is correct |
10 |
Correct |
34 ms |
7248 KB |
Output is correct |
11 |
Correct |
43 ms |
7252 KB |
Output is correct |
12 |
Correct |
34 ms |
7768 KB |
Output is correct |
13 |
Correct |
33 ms |
7844 KB |
Output is correct |
14 |
Correct |
32 ms |
6996 KB |
Output is correct |
15 |
Correct |
92 ms |
10824 KB |
Output is correct |
16 |
Correct |
102 ms |
10656 KB |
Output is correct |
17 |
Correct |
100 ms |
11296 KB |
Output is correct |
18 |
Correct |
79 ms |
11092 KB |
Output is correct |
19 |
Correct |
76 ms |
11172 KB |
Output is correct |
20 |
Correct |
76 ms |
12084 KB |
Output is correct |
21 |
Correct |
91 ms |
12404 KB |
Output is correct |
22 |
Correct |
90 ms |
11932 KB |
Output is correct |
23 |
Correct |
76 ms |
12200 KB |
Output is correct |
24 |
Correct |
80 ms |
12176 KB |
Output is correct |
25 |
Correct |
77 ms |
12116 KB |
Output is correct |
26 |
Correct |
76 ms |
11956 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2500 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
5 ms |
3164 KB |
Output is correct |
37 |
Correct |
34 ms |
7648 KB |
Output is correct |
38 |
Correct |
33 ms |
7508 KB |
Output is correct |
39 |
Correct |
33 ms |
7504 KB |
Output is correct |
40 |
Correct |
32 ms |
7504 KB |
Output is correct |
41 |
Correct |
34 ms |
7504 KB |
Output is correct |
42 |
Correct |
32 ms |
7128 KB |
Output is correct |
43 |
Correct |
33 ms |
7888 KB |
Output is correct |
44 |
Correct |
33 ms |
7516 KB |
Output is correct |
45 |
Correct |
32 ms |
7516 KB |
Output is correct |
46 |
Correct |
34 ms |
7772 KB |
Output is correct |
47 |
Correct |
10 ms |
3608 KB |
Output is correct |
48 |
Correct |
97 ms |
11972 KB |
Output is correct |
49 |
Correct |
92 ms |
11944 KB |
Output is correct |
50 |
Correct |
117 ms |
12104 KB |
Output is correct |
51 |
Correct |
91 ms |
11884 KB |
Output is correct |
52 |
Correct |
88 ms |
11764 KB |
Output is correct |
53 |
Correct |
82 ms |
11708 KB |
Output is correct |
54 |
Correct |
106 ms |
12924 KB |
Output is correct |
55 |
Correct |
95 ms |
12100 KB |
Output is correct |
56 |
Correct |
80 ms |
11964 KB |
Output is correct |
57 |
Correct |
92 ms |
12956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
28 ms |
6576 KB |
Output is correct |
11 |
Correct |
34 ms |
7248 KB |
Output is correct |
12 |
Correct |
43 ms |
7252 KB |
Output is correct |
13 |
Correct |
34 ms |
7768 KB |
Output is correct |
14 |
Correct |
33 ms |
7844 KB |
Output is correct |
15 |
Correct |
32 ms |
6996 KB |
Output is correct |
16 |
Correct |
92 ms |
10824 KB |
Output is correct |
17 |
Correct |
102 ms |
10656 KB |
Output is correct |
18 |
Correct |
100 ms |
11296 KB |
Output is correct |
19 |
Correct |
79 ms |
11092 KB |
Output is correct |
20 |
Correct |
76 ms |
11172 KB |
Output is correct |
21 |
Correct |
76 ms |
12084 KB |
Output is correct |
22 |
Correct |
91 ms |
12404 KB |
Output is correct |
23 |
Correct |
90 ms |
11932 KB |
Output is correct |
24 |
Correct |
76 ms |
12200 KB |
Output is correct |
25 |
Correct |
80 ms |
12176 KB |
Output is correct |
26 |
Correct |
77 ms |
12116 KB |
Output is correct |
27 |
Correct |
76 ms |
11956 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2500 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
5 ms |
3164 KB |
Output is correct |
38 |
Correct |
34 ms |
7648 KB |
Output is correct |
39 |
Correct |
33 ms |
7508 KB |
Output is correct |
40 |
Correct |
33 ms |
7504 KB |
Output is correct |
41 |
Correct |
32 ms |
7504 KB |
Output is correct |
42 |
Correct |
34 ms |
7504 KB |
Output is correct |
43 |
Correct |
32 ms |
7128 KB |
Output is correct |
44 |
Correct |
33 ms |
7888 KB |
Output is correct |
45 |
Correct |
33 ms |
7516 KB |
Output is correct |
46 |
Correct |
32 ms |
7516 KB |
Output is correct |
47 |
Correct |
34 ms |
7772 KB |
Output is correct |
48 |
Correct |
10 ms |
3608 KB |
Output is correct |
49 |
Correct |
97 ms |
11972 KB |
Output is correct |
50 |
Correct |
92 ms |
11944 KB |
Output is correct |
51 |
Correct |
117 ms |
12104 KB |
Output is correct |
52 |
Correct |
91 ms |
11884 KB |
Output is correct |
53 |
Correct |
88 ms |
11764 KB |
Output is correct |
54 |
Correct |
82 ms |
11708 KB |
Output is correct |
55 |
Correct |
106 ms |
12924 KB |
Output is correct |
56 |
Correct |
95 ms |
12100 KB |
Output is correct |
57 |
Correct |
80 ms |
11964 KB |
Output is correct |
58 |
Correct |
92 ms |
12956 KB |
Output is correct |
59 |
Correct |
52 ms |
8156 KB |
Output is correct |
60 |
Correct |
91 ms |
11604 KB |
Output is correct |
61 |
Correct |
97 ms |
11856 KB |
Output is correct |
62 |
Correct |
97 ms |
12180 KB |
Output is correct |
63 |
Correct |
84 ms |
12188 KB |
Output is correct |
64 |
Correct |
1 ms |
2500 KB |
Output is correct |
65 |
Correct |
1 ms |
2392 KB |
Output is correct |
66 |
Correct |
1 ms |
2396 KB |
Output is correct |
67 |
Correct |
1 ms |
2396 KB |
Output is correct |
68 |
Correct |
1 ms |
2392 KB |
Output is correct |
69 |
Correct |
1 ms |
2396 KB |
Output is correct |
70 |
Correct |
1 ms |
2396 KB |
Output is correct |
71 |
Correct |
1 ms |
2396 KB |
Output is correct |
72 |
Correct |
1 ms |
2396 KB |
Output is correct |
73 |
Correct |
1 ms |
2396 KB |
Output is correct |
74 |
Correct |
51 ms |
10104 KB |
Output is correct |
75 |
Correct |
37 ms |
7504 KB |
Output is correct |
76 |
Correct |
32 ms |
7504 KB |
Output is correct |
77 |
Correct |
37 ms |
7876 KB |
Output is correct |
78 |
Correct |
52 ms |
9568 KB |
Output is correct |
79 |
Correct |
48 ms |
8016 KB |
Output is correct |
80 |
Correct |
50 ms |
9140 KB |
Output is correct |
81 |
Correct |
57 ms |
10832 KB |
Output is correct |
82 |
Correct |
72 ms |
11692 KB |
Output is correct |
83 |
Correct |
72 ms |
12480 KB |
Output is correct |
84 |
Correct |
32 ms |
7516 KB |
Output is correct |
85 |
Correct |
62 ms |
11560 KB |
Output is correct |
86 |
Correct |
31 ms |
6024 KB |
Output is correct |
87 |
Correct |
93 ms |
12076 KB |
Output is correct |
88 |
Correct |
92 ms |
12076 KB |
Output is correct |
89 |
Correct |
87 ms |
12212 KB |
Output is correct |
90 |
Correct |
106 ms |
13136 KB |
Output is correct |
91 |
Correct |
101 ms |
13288 KB |
Output is correct |
92 |
Correct |
96 ms |
13372 KB |
Output is correct |
93 |
Correct |
120 ms |
15068 KB |
Output is correct |
94 |
Correct |
124 ms |
15488 KB |
Output is correct |
95 |
Correct |
142 ms |
16208 KB |
Output is correct |
96 |
Correct |
83 ms |
12088 KB |
Output is correct |
97 |
Correct |
105 ms |
14100 KB |
Output is correct |