#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#define ll long long
#define pii pair<ll,ll>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
using namespace std;
const int mxn=3e5+5;
int pr[mxn];
int up[mxn][20]{0};
int dep[mxn]{0},d[mxn]{0};
vector<int>g[mxn];
int dp[mxn]{0};
bool vis[mxn]{0},ok=0;
int get(int r){
return pr[r]==r?r:pr[r]=get(pr[r]);
}
void dfs(int u,int p,int l){
up[u][0]=p;dep[u]=l;
for(int i=1;i<20;i++)up[u][i]=up[up[u][i-1]][i-1];
for(auto v:g[u]){
if(v==p)continue;
if(!vis[v])vis[v]=1,dp[v]=dp[u];
dfs(v,u,l+1);
}
}
int get(int a,int b){
if(dep[a]>dep[b])swap(a,b);
for(int i=19;i>=0;i--)if(dep[b]-(1<<i)>=dep[a])b=up[b][i];
if(a==b)return a;
for(int i=19;i>=0;i--)if(up[a][i]!=up[b][i])a=up[a][i],b=up[b][i];
return up[a][0];
}
void init(int N,int M,vi U,vi V,vi W){
vector<pair<int,pii>>edge;iota(pr,pr+N,0);
for(int i=0;i<M;i++)edge.pb({W[i],{U[i],V[i]}});
sort(edge.begin(),edge.end());
int cr=N-1;
for(auto it : edge){
cr++;pr[cr]=cr;dp[cr]=it.f;
d[it.s.f]++;d[it.s.s]++;
int x=get(it.s.f),y=get(it.s.s);
pr[x]=cr;pr[y]=cr;
if(x==y){g[cr].pb(x);vis[cr]=1;continue;}
g[cr].pb(x);g[cr].pb(y);
if(d[it.s.f]>=3||d[it.s.s]>=3||vis[x]||vis[y])vis[cr]=1;
}if(!vis[cr])return;ok=1;
dfs(cr,cr,0);
}
int getMinimumFuelCapacity(int X, int Y) {
if(!ok)return -1;
return dp[get(X,Y)];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7516 KB |
Output is correct |
2 |
Correct |
3 ms |
7516 KB |
Output is correct |
3 |
Correct |
3 ms |
7352 KB |
Output is correct |
4 |
Correct |
3 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
3 ms |
7516 KB |
Output is correct |
7 |
Correct |
3 ms |
7532 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
34 ms |
16332 KB |
Output is correct |
10 |
Correct |
43 ms |
18368 KB |
Output is correct |
11 |
Correct |
39 ms |
18368 KB |
Output is correct |
12 |
Correct |
46 ms |
18880 KB |
Output is correct |
13 |
Correct |
39 ms |
19392 KB |
Output is correct |
14 |
Correct |
38 ms |
16832 KB |
Output is correct |
15 |
Correct |
75 ms |
22456 KB |
Output is correct |
16 |
Correct |
78 ms |
22176 KB |
Output is correct |
17 |
Correct |
76 ms |
22732 KB |
Output is correct |
18 |
Correct |
80 ms |
23488 KB |
Output is correct |
19 |
Correct |
57 ms |
16580 KB |
Output is correct |
20 |
Correct |
140 ms |
38696 KB |
Output is correct |
21 |
Correct |
142 ms |
37828 KB |
Output is correct |
22 |
Correct |
134 ms |
39872 KB |
Output is correct |
23 |
Correct |
186 ms |
43616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7516 KB |
Output is correct |
2 |
Correct |
3 ms |
7516 KB |
Output is correct |
3 |
Correct |
150 ms |
45252 KB |
Output is correct |
4 |
Correct |
154 ms |
46784 KB |
Output is correct |
5 |
Correct |
156 ms |
45964 KB |
Output is correct |
6 |
Correct |
144 ms |
46784 KB |
Output is correct |
7 |
Correct |
153 ms |
46268 KB |
Output is correct |
8 |
Correct |
144 ms |
44744 KB |
Output is correct |
9 |
Correct |
137 ms |
46020 KB |
Output is correct |
10 |
Correct |
143 ms |
44484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7516 KB |
Output is correct |
2 |
Correct |
3 ms |
7516 KB |
Output is correct |
3 |
Correct |
3 ms |
7352 KB |
Output is correct |
4 |
Correct |
3 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
3 ms |
7516 KB |
Output is correct |
7 |
Correct |
3 ms |
7532 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
3 ms |
7516 KB |
Output is correct |
10 |
Correct |
4 ms |
7772 KB |
Output is correct |
11 |
Correct |
3 ms |
7772 KB |
Output is correct |
12 |
Correct |
4 ms |
8024 KB |
Output is correct |
13 |
Correct |
3 ms |
7516 KB |
Output is correct |
14 |
Correct |
4 ms |
7772 KB |
Output is correct |
15 |
Correct |
3 ms |
7772 KB |
Output is correct |
16 |
Correct |
3 ms |
7784 KB |
Output is correct |
17 |
Correct |
3 ms |
7772 KB |
Output is correct |
18 |
Correct |
3 ms |
7768 KB |
Output is correct |
19 |
Correct |
4 ms |
7772 KB |
Output is correct |
20 |
Correct |
3 ms |
7772 KB |
Output is correct |
21 |
Correct |
4 ms |
7772 KB |
Output is correct |
22 |
Correct |
4 ms |
7768 KB |
Output is correct |
23 |
Correct |
3 ms |
7516 KB |
Output is correct |
24 |
Correct |
3 ms |
7772 KB |
Output is correct |
25 |
Correct |
4 ms |
8024 KB |
Output is correct |
26 |
Correct |
4 ms |
8028 KB |
Output is correct |
27 |
Correct |
3 ms |
7772 KB |
Output is correct |
28 |
Correct |
4 ms |
8028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7516 KB |
Output is correct |
2 |
Correct |
3 ms |
7516 KB |
Output is correct |
3 |
Correct |
3 ms |
7516 KB |
Output is correct |
4 |
Correct |
3 ms |
7352 KB |
Output is correct |
5 |
Correct |
3 ms |
7516 KB |
Output is correct |
6 |
Correct |
4 ms |
7516 KB |
Output is correct |
7 |
Correct |
3 ms |
7516 KB |
Output is correct |
8 |
Correct |
3 ms |
7532 KB |
Output is correct |
9 |
Correct |
4 ms |
7516 KB |
Output is correct |
10 |
Correct |
34 ms |
16332 KB |
Output is correct |
11 |
Correct |
43 ms |
18368 KB |
Output is correct |
12 |
Correct |
39 ms |
18368 KB |
Output is correct |
13 |
Correct |
46 ms |
18880 KB |
Output is correct |
14 |
Correct |
39 ms |
19392 KB |
Output is correct |
15 |
Correct |
4 ms |
7772 KB |
Output is correct |
16 |
Correct |
3 ms |
7772 KB |
Output is correct |
17 |
Correct |
4 ms |
8024 KB |
Output is correct |
18 |
Correct |
3 ms |
7516 KB |
Output is correct |
19 |
Correct |
4 ms |
7772 KB |
Output is correct |
20 |
Correct |
3 ms |
7772 KB |
Output is correct |
21 |
Correct |
3 ms |
7784 KB |
Output is correct |
22 |
Correct |
3 ms |
7772 KB |
Output is correct |
23 |
Correct |
3 ms |
7768 KB |
Output is correct |
24 |
Correct |
4 ms |
7772 KB |
Output is correct |
25 |
Correct |
3 ms |
7772 KB |
Output is correct |
26 |
Correct |
4 ms |
7772 KB |
Output is correct |
27 |
Correct |
4 ms |
7768 KB |
Output is correct |
28 |
Correct |
3 ms |
7516 KB |
Output is correct |
29 |
Correct |
3 ms |
7772 KB |
Output is correct |
30 |
Correct |
4 ms |
8024 KB |
Output is correct |
31 |
Correct |
4 ms |
8028 KB |
Output is correct |
32 |
Correct |
3 ms |
7772 KB |
Output is correct |
33 |
Correct |
4 ms |
8028 KB |
Output is correct |
34 |
Correct |
12 ms |
11352 KB |
Output is correct |
35 |
Correct |
71 ms |
35660 KB |
Output is correct |
36 |
Correct |
74 ms |
35524 KB |
Output is correct |
37 |
Correct |
65 ms |
35520 KB |
Output is correct |
38 |
Correct |
65 ms |
35264 KB |
Output is correct |
39 |
Correct |
62 ms |
35008 KB |
Output is correct |
40 |
Correct |
57 ms |
32960 KB |
Output is correct |
41 |
Correct |
64 ms |
36032 KB |
Output is correct |
42 |
Correct |
72 ms |
35528 KB |
Output is correct |
43 |
Correct |
61 ms |
40896 KB |
Output is correct |
44 |
Correct |
66 ms |
36116 KB |
Output is correct |
45 |
Correct |
98 ms |
50100 KB |
Output is correct |
46 |
Correct |
71 ms |
35748 KB |
Output is correct |
47 |
Correct |
68 ms |
35916 KB |
Output is correct |
48 |
Correct |
77 ms |
40388 KB |
Output is correct |
49 |
Correct |
79 ms |
49332 KB |
Output is correct |
50 |
Correct |
62 ms |
39872 KB |
Output is correct |
51 |
Correct |
79 ms |
44440 KB |
Output is correct |
52 |
Correct |
105 ms |
52364 KB |
Output is correct |
53 |
Correct |
116 ms |
55476 KB |
Output is correct |
54 |
Correct |
130 ms |
62432 KB |
Output is correct |
55 |
Correct |
61 ms |
40384 KB |
Output is correct |
56 |
Correct |
124 ms |
57592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7516 KB |
Output is correct |
2 |
Correct |
3 ms |
7516 KB |
Output is correct |
3 |
Correct |
3 ms |
7352 KB |
Output is correct |
4 |
Correct |
3 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Correct |
3 ms |
7516 KB |
Output is correct |
7 |
Correct |
3 ms |
7532 KB |
Output is correct |
8 |
Correct |
4 ms |
7516 KB |
Output is correct |
9 |
Correct |
34 ms |
16332 KB |
Output is correct |
10 |
Correct |
43 ms |
18368 KB |
Output is correct |
11 |
Correct |
39 ms |
18368 KB |
Output is correct |
12 |
Correct |
46 ms |
18880 KB |
Output is correct |
13 |
Correct |
39 ms |
19392 KB |
Output is correct |
14 |
Correct |
38 ms |
16832 KB |
Output is correct |
15 |
Correct |
75 ms |
22456 KB |
Output is correct |
16 |
Correct |
78 ms |
22176 KB |
Output is correct |
17 |
Correct |
76 ms |
22732 KB |
Output is correct |
18 |
Correct |
80 ms |
23488 KB |
Output is correct |
19 |
Correct |
150 ms |
45252 KB |
Output is correct |
20 |
Correct |
154 ms |
46784 KB |
Output is correct |
21 |
Correct |
156 ms |
45964 KB |
Output is correct |
22 |
Correct |
144 ms |
46784 KB |
Output is correct |
23 |
Correct |
153 ms |
46268 KB |
Output is correct |
24 |
Correct |
144 ms |
44744 KB |
Output is correct |
25 |
Correct |
137 ms |
46020 KB |
Output is correct |
26 |
Correct |
143 ms |
44484 KB |
Output is correct |
27 |
Correct |
4 ms |
7772 KB |
Output is correct |
28 |
Correct |
3 ms |
7772 KB |
Output is correct |
29 |
Correct |
4 ms |
8024 KB |
Output is correct |
30 |
Correct |
3 ms |
7516 KB |
Output is correct |
31 |
Correct |
4 ms |
7772 KB |
Output is correct |
32 |
Correct |
3 ms |
7772 KB |
Output is correct |
33 |
Correct |
3 ms |
7784 KB |
Output is correct |
34 |
Correct |
3 ms |
7772 KB |
Output is correct |
35 |
Correct |
3 ms |
7768 KB |
Output is correct |
36 |
Correct |
12 ms |
11352 KB |
Output is correct |
37 |
Correct |
71 ms |
35660 KB |
Output is correct |
38 |
Correct |
74 ms |
35524 KB |
Output is correct |
39 |
Correct |
65 ms |
35520 KB |
Output is correct |
40 |
Correct |
65 ms |
35264 KB |
Output is correct |
41 |
Correct |
62 ms |
35008 KB |
Output is correct |
42 |
Correct |
57 ms |
32960 KB |
Output is correct |
43 |
Correct |
64 ms |
36032 KB |
Output is correct |
44 |
Correct |
72 ms |
35528 KB |
Output is correct |
45 |
Correct |
61 ms |
40896 KB |
Output is correct |
46 |
Correct |
66 ms |
36116 KB |
Output is correct |
47 |
Correct |
15 ms |
11352 KB |
Output is correct |
48 |
Correct |
135 ms |
39544 KB |
Output is correct |
49 |
Correct |
148 ms |
39616 KB |
Output is correct |
50 |
Correct |
134 ms |
39372 KB |
Output is correct |
51 |
Correct |
132 ms |
39360 KB |
Output is correct |
52 |
Correct |
129 ms |
37568 KB |
Output is correct |
53 |
Correct |
125 ms |
30512 KB |
Output is correct |
54 |
Correct |
143 ms |
39912 KB |
Output is correct |
55 |
Correct |
135 ms |
39616 KB |
Output is correct |
56 |
Correct |
193 ms |
43716 KB |
Output is correct |
57 |
Correct |
150 ms |
40008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
7516 KB |
Output is correct |
2 |
Correct |
3 ms |
7516 KB |
Output is correct |
3 |
Correct |
3 ms |
7516 KB |
Output is correct |
4 |
Correct |
3 ms |
7352 KB |
Output is correct |
5 |
Correct |
3 ms |
7516 KB |
Output is correct |
6 |
Correct |
4 ms |
7516 KB |
Output is correct |
7 |
Correct |
3 ms |
7516 KB |
Output is correct |
8 |
Correct |
3 ms |
7532 KB |
Output is correct |
9 |
Correct |
4 ms |
7516 KB |
Output is correct |
10 |
Correct |
34 ms |
16332 KB |
Output is correct |
11 |
Correct |
43 ms |
18368 KB |
Output is correct |
12 |
Correct |
39 ms |
18368 KB |
Output is correct |
13 |
Correct |
46 ms |
18880 KB |
Output is correct |
14 |
Correct |
39 ms |
19392 KB |
Output is correct |
15 |
Correct |
38 ms |
16832 KB |
Output is correct |
16 |
Correct |
75 ms |
22456 KB |
Output is correct |
17 |
Correct |
78 ms |
22176 KB |
Output is correct |
18 |
Correct |
76 ms |
22732 KB |
Output is correct |
19 |
Correct |
80 ms |
23488 KB |
Output is correct |
20 |
Correct |
150 ms |
45252 KB |
Output is correct |
21 |
Correct |
154 ms |
46784 KB |
Output is correct |
22 |
Correct |
156 ms |
45964 KB |
Output is correct |
23 |
Correct |
144 ms |
46784 KB |
Output is correct |
24 |
Correct |
153 ms |
46268 KB |
Output is correct |
25 |
Correct |
144 ms |
44744 KB |
Output is correct |
26 |
Correct |
137 ms |
46020 KB |
Output is correct |
27 |
Correct |
143 ms |
44484 KB |
Output is correct |
28 |
Correct |
4 ms |
7772 KB |
Output is correct |
29 |
Correct |
3 ms |
7772 KB |
Output is correct |
30 |
Correct |
4 ms |
8024 KB |
Output is correct |
31 |
Correct |
3 ms |
7516 KB |
Output is correct |
32 |
Correct |
4 ms |
7772 KB |
Output is correct |
33 |
Correct |
3 ms |
7772 KB |
Output is correct |
34 |
Correct |
3 ms |
7784 KB |
Output is correct |
35 |
Correct |
3 ms |
7772 KB |
Output is correct |
36 |
Correct |
3 ms |
7768 KB |
Output is correct |
37 |
Correct |
12 ms |
11352 KB |
Output is correct |
38 |
Correct |
71 ms |
35660 KB |
Output is correct |
39 |
Correct |
74 ms |
35524 KB |
Output is correct |
40 |
Correct |
65 ms |
35520 KB |
Output is correct |
41 |
Correct |
65 ms |
35264 KB |
Output is correct |
42 |
Correct |
62 ms |
35008 KB |
Output is correct |
43 |
Correct |
57 ms |
32960 KB |
Output is correct |
44 |
Correct |
64 ms |
36032 KB |
Output is correct |
45 |
Correct |
72 ms |
35528 KB |
Output is correct |
46 |
Correct |
61 ms |
40896 KB |
Output is correct |
47 |
Correct |
66 ms |
36116 KB |
Output is correct |
48 |
Correct |
15 ms |
11352 KB |
Output is correct |
49 |
Correct |
135 ms |
39544 KB |
Output is correct |
50 |
Correct |
148 ms |
39616 KB |
Output is correct |
51 |
Correct |
134 ms |
39372 KB |
Output is correct |
52 |
Correct |
132 ms |
39360 KB |
Output is correct |
53 |
Correct |
129 ms |
37568 KB |
Output is correct |
54 |
Correct |
125 ms |
30512 KB |
Output is correct |
55 |
Correct |
143 ms |
39912 KB |
Output is correct |
56 |
Correct |
135 ms |
39616 KB |
Output is correct |
57 |
Correct |
193 ms |
43716 KB |
Output is correct |
58 |
Correct |
150 ms |
40008 KB |
Output is correct |
59 |
Correct |
57 ms |
16580 KB |
Output is correct |
60 |
Correct |
140 ms |
38696 KB |
Output is correct |
61 |
Correct |
142 ms |
37828 KB |
Output is correct |
62 |
Correct |
134 ms |
39872 KB |
Output is correct |
63 |
Correct |
186 ms |
43616 KB |
Output is correct |
64 |
Correct |
4 ms |
7772 KB |
Output is correct |
65 |
Correct |
3 ms |
7772 KB |
Output is correct |
66 |
Correct |
4 ms |
7772 KB |
Output is correct |
67 |
Correct |
4 ms |
7768 KB |
Output is correct |
68 |
Correct |
3 ms |
7516 KB |
Output is correct |
69 |
Correct |
3 ms |
7772 KB |
Output is correct |
70 |
Correct |
4 ms |
8024 KB |
Output is correct |
71 |
Correct |
4 ms |
8028 KB |
Output is correct |
72 |
Correct |
3 ms |
7772 KB |
Output is correct |
73 |
Correct |
4 ms |
8028 KB |
Output is correct |
74 |
Correct |
98 ms |
50100 KB |
Output is correct |
75 |
Correct |
71 ms |
35748 KB |
Output is correct |
76 |
Correct |
68 ms |
35916 KB |
Output is correct |
77 |
Correct |
77 ms |
40388 KB |
Output is correct |
78 |
Correct |
79 ms |
49332 KB |
Output is correct |
79 |
Correct |
62 ms |
39872 KB |
Output is correct |
80 |
Correct |
79 ms |
44440 KB |
Output is correct |
81 |
Correct |
105 ms |
52364 KB |
Output is correct |
82 |
Correct |
116 ms |
55476 KB |
Output is correct |
83 |
Correct |
130 ms |
62432 KB |
Output is correct |
84 |
Correct |
61 ms |
40384 KB |
Output is correct |
85 |
Correct |
124 ms |
57592 KB |
Output is correct |
86 |
Correct |
53 ms |
22980 KB |
Output is correct |
87 |
Correct |
147 ms |
39524 KB |
Output is correct |
88 |
Correct |
139 ms |
39620 KB |
Output is correct |
89 |
Correct |
165 ms |
43052 KB |
Output is correct |
90 |
Correct |
153 ms |
55148 KB |
Output is correct |
91 |
Correct |
159 ms |
51200 KB |
Output is correct |
92 |
Correct |
174 ms |
46788 KB |
Output is correct |
93 |
Correct |
192 ms |
55620 KB |
Output is correct |
94 |
Correct |
215 ms |
59316 KB |
Output is correct |
95 |
Correct |
203 ms |
66296 KB |
Output is correct |
96 |
Correct |
175 ms |
43968 KB |
Output is correct |
97 |
Correct |
199 ms |
51328 KB |
Output is correct |