#include <bits/stdc++.h>
#include "swap.h"
#define MAX 305000
int n,m;
typedef std::pair<int,int> pii;
typedef std::pair<int,pii> pip;
std::vector<pip> tmp;
std::vector<pii> con[MAX];
int pai[MAX];
bool acabou[MAX];
std::vector<int> candidatos[MAX];
std::vector<int> unicos[MAX];
int conexoes[MAX];
int fins[MAX];
int up[MAX][25];
int ph[MAX][25];
int prof[MAX];
void dfs(int pos,int prev,int peso,int depth){
prof[pos]=depth;
up[pos][0]=prev;
ph[pos][0]=peso;
for(auto&x:con[pos]){
if(x.first==prev)continue;
dfs(x.first,pos,x.second,depth+1);
}
}
int find(int a){
if(pai[a]==a)
return a;
return pai[a]=find(pai[a]);
}
int peso=0;
void Union(int a,int b){
conexoes[a]++;
conexoes[b]++;
a=find(a);
b=find(b);
if(a==b)acabou[a]=true;
else {
con[a].push_back({b,peso});
con[b].push_back({a,peso});
pai[b]=a;
if(candidatos[b]>candidatos[a])std::swap(candidatos[a],candidatos[b]);
for(auto&x:candidatos[b]){
candidatos[a].push_back(x);
}
for(auto&x:unicos[b]){
unicos[a].push_back(x);
}
unicos[b].clear();
candidatos[b].clear();
acabou[a]=std::max(acabou[a],acabou[b]);
}
assert(unicos[a].size()<=4);
{
std::vector<int> v;
for(auto&x:unicos[a]){
if(conexoes[x]==1)v.push_back(x);
}
unicos[a]=v;
}
if(unicos[a].size()>2)acabou[a]=true;
if(acabou[a]){
for(auto&x:candidatos[a])fins[x]=peso;
candidatos[a].clear();
unicos[a].clear();
return;
}
}
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){
tmp.push_back({W[i],{U[i],V[i]}});
}
std::sort(tmp.begin(),tmp.end());
for(auto&x:fins)x=1e9;
for(int i=0;i!=N;++i){
pai[i]=i;
candidatos[i].push_back(i);
unicos[i].push_back(i);
}
for(auto&x:tmp){
peso=x.first;
int u = x.second.first,v=x.second.second;
Union(u,v);
}
dfs(0,-1,-1,0);
for(int j=1;j!=25;++j){
for(int i=0;i!=N;++i){
if(up[i][j-1]==-1){
up[i][j]=-1;
continue;
}
up[i][j]=up[up[i][j-1]][j-1];
ph[i][j]=std::max(ph[up[i][j-1]][j-1],ph[i][j-1]);
}
}
/* for(int i=0;i!=N;++i){
std::cout<<fins[i]<<" ";
}
std::cout<<"\n";*/
}
int lcaval(int x,int y){
if(prof[y]<prof[x])std::swap(x,y);
int ans=0;
for(int i=24;i!=-1;--i){
int prox = up[y][i];
if(prox==-1)continue;
if(prof[prox]>=prof[x]){
ans=std::max(ans,ph[y][i]);
y=prox;
}
}
assert(prof[x]==prof[y]);
/// std::cout<<x<<" "<<y<<"preprof\n";
for(int i=24;i!=-1;--i){
int a = up[y][i];
int b = up[x][i];
if(a==-1||b==-1)continue;
if(a!=b){
ans=std::max(ans,ph[y][i]);
ans=std::max(ans,ph[x][i]);
x=b;
y=a;
}
}
/// std::cout<<x<<" "<<y<<"<-\n";
if(x!=y){
ans=std::max(ans,ph[y][0]);
ans=std::max(ans,ph[x][0]);
x=up[x][0];
y=up[y][0];
}
///assert(x==y);
/// std::cout<<"Retorna "<<ans<<"\n";
/// std::cout<<x<<" "<<y<<"\n";
return ans;
}
int getMinimumFuelCapacity(int X, int Y) {
if(fins[X]==1e9&&fins[Y]==1e9)return -1;
///Proxima etapa: Achar o peso minimo entre o caminho de X e Y, a resposta sera max(min(fins[X],fins[Y]),caminho)
int ans = std::min(fins[X],fins[Y]);
return std::max(ans,lcaval(X,Y));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
22928 KB |
Output is correct |
2 |
Correct |
12 ms |
22988 KB |
Output is correct |
3 |
Correct |
12 ms |
23004 KB |
Output is correct |
4 |
Correct |
12 ms |
23152 KB |
Output is correct |
5 |
Correct |
13 ms |
23324 KB |
Output is correct |
6 |
Correct |
12 ms |
23260 KB |
Output is correct |
7 |
Correct |
13 ms |
23332 KB |
Output is correct |
8 |
Correct |
13 ms |
23372 KB |
Output is correct |
9 |
Correct |
157 ms |
53800 KB |
Output is correct |
10 |
Correct |
204 ms |
60224 KB |
Output is correct |
11 |
Correct |
185 ms |
59656 KB |
Output is correct |
12 |
Correct |
194 ms |
62124 KB |
Output is correct |
13 |
Correct |
169 ms |
61368 KB |
Output is correct |
14 |
Correct |
146 ms |
55628 KB |
Output is correct |
15 |
Correct |
232 ms |
67220 KB |
Output is correct |
16 |
Correct |
228 ms |
65940 KB |
Output is correct |
17 |
Correct |
256 ms |
68608 KB |
Output is correct |
18 |
Correct |
212 ms |
66684 KB |
Output is correct |
19 |
Correct |
96 ms |
34436 KB |
Output is correct |
20 |
Correct |
322 ms |
68048 KB |
Output is correct |
21 |
Correct |
296 ms |
67116 KB |
Output is correct |
22 |
Correct |
326 ms |
69916 KB |
Output is correct |
23 |
Correct |
412 ms |
67744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
22928 KB |
Output is correct |
2 |
Correct |
12 ms |
22988 KB |
Output is correct |
3 |
Correct |
212 ms |
58588 KB |
Output is correct |
4 |
Correct |
225 ms |
64120 KB |
Output is correct |
5 |
Correct |
223 ms |
63184 KB |
Output is correct |
6 |
Correct |
224 ms |
63868 KB |
Output is correct |
7 |
Correct |
224 ms |
63692 KB |
Output is correct |
8 |
Correct |
242 ms |
62184 KB |
Output is correct |
9 |
Correct |
218 ms |
63332 KB |
Output is correct |
10 |
Correct |
215 ms |
61812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
22928 KB |
Output is correct |
2 |
Correct |
12 ms |
22988 KB |
Output is correct |
3 |
Correct |
12 ms |
23004 KB |
Output is correct |
4 |
Correct |
12 ms |
23152 KB |
Output is correct |
5 |
Correct |
13 ms |
23324 KB |
Output is correct |
6 |
Correct |
12 ms |
23260 KB |
Output is correct |
7 |
Correct |
13 ms |
23332 KB |
Output is correct |
8 |
Correct |
13 ms |
23372 KB |
Output is correct |
9 |
Correct |
12 ms |
22988 KB |
Output is correct |
10 |
Correct |
13 ms |
23248 KB |
Output is correct |
11 |
Correct |
12 ms |
23372 KB |
Output is correct |
12 |
Correct |
12 ms |
23344 KB |
Output is correct |
13 |
Correct |
12 ms |
23244 KB |
Output is correct |
14 |
Correct |
12 ms |
23268 KB |
Output is correct |
15 |
Correct |
13 ms |
23344 KB |
Output is correct |
16 |
Correct |
13 ms |
23372 KB |
Output is correct |
17 |
Correct |
12 ms |
23344 KB |
Output is correct |
18 |
Correct |
13 ms |
23244 KB |
Output is correct |
19 |
Correct |
12 ms |
23244 KB |
Output is correct |
20 |
Correct |
13 ms |
23340 KB |
Output is correct |
21 |
Correct |
13 ms |
23320 KB |
Output is correct |
22 |
Correct |
13 ms |
23108 KB |
Output is correct |
23 |
Correct |
12 ms |
23208 KB |
Output is correct |
24 |
Correct |
13 ms |
23412 KB |
Output is correct |
25 |
Correct |
13 ms |
23340 KB |
Output is correct |
26 |
Correct |
14 ms |
23340 KB |
Output is correct |
27 |
Correct |
12 ms |
23332 KB |
Output is correct |
28 |
Correct |
13 ms |
23372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
22988 KB |
Output is correct |
2 |
Correct |
12 ms |
22928 KB |
Output is correct |
3 |
Correct |
12 ms |
22988 KB |
Output is correct |
4 |
Correct |
12 ms |
23004 KB |
Output is correct |
5 |
Correct |
12 ms |
23152 KB |
Output is correct |
6 |
Correct |
13 ms |
23324 KB |
Output is correct |
7 |
Correct |
12 ms |
23260 KB |
Output is correct |
8 |
Correct |
13 ms |
23332 KB |
Output is correct |
9 |
Correct |
13 ms |
23372 KB |
Output is correct |
10 |
Correct |
157 ms |
53800 KB |
Output is correct |
11 |
Correct |
204 ms |
60224 KB |
Output is correct |
12 |
Correct |
185 ms |
59656 KB |
Output is correct |
13 |
Correct |
194 ms |
62124 KB |
Output is correct |
14 |
Correct |
169 ms |
61368 KB |
Output is correct |
15 |
Correct |
13 ms |
23248 KB |
Output is correct |
16 |
Correct |
12 ms |
23372 KB |
Output is correct |
17 |
Correct |
12 ms |
23344 KB |
Output is correct |
18 |
Correct |
12 ms |
23244 KB |
Output is correct |
19 |
Correct |
12 ms |
23268 KB |
Output is correct |
20 |
Correct |
13 ms |
23344 KB |
Output is correct |
21 |
Correct |
13 ms |
23372 KB |
Output is correct |
22 |
Correct |
12 ms |
23344 KB |
Output is correct |
23 |
Correct |
13 ms |
23244 KB |
Output is correct |
24 |
Correct |
12 ms |
23244 KB |
Output is correct |
25 |
Correct |
13 ms |
23340 KB |
Output is correct |
26 |
Correct |
13 ms |
23320 KB |
Output is correct |
27 |
Correct |
13 ms |
23108 KB |
Output is correct |
28 |
Correct |
12 ms |
23208 KB |
Output is correct |
29 |
Correct |
13 ms |
23412 KB |
Output is correct |
30 |
Correct |
13 ms |
23340 KB |
Output is correct |
31 |
Correct |
14 ms |
23340 KB |
Output is correct |
32 |
Correct |
12 ms |
23332 KB |
Output is correct |
33 |
Correct |
13 ms |
23372 KB |
Output is correct |
34 |
Correct |
26 ms |
27884 KB |
Output is correct |
35 |
Correct |
189 ms |
62444 KB |
Output is correct |
36 |
Correct |
206 ms |
62264 KB |
Output is correct |
37 |
Correct |
188 ms |
61112 KB |
Output is correct |
38 |
Correct |
186 ms |
59920 KB |
Output is correct |
39 |
Correct |
192 ms |
59124 KB |
Output is correct |
40 |
Correct |
154 ms |
55736 KB |
Output is correct |
41 |
Correct |
188 ms |
63684 KB |
Output is correct |
42 |
Correct |
198 ms |
63896 KB |
Output is correct |
43 |
Correct |
154 ms |
60940 KB |
Output is correct |
44 |
Correct |
181 ms |
59648 KB |
Output is correct |
45 |
Correct |
168 ms |
56140 KB |
Output is correct |
46 |
Correct |
188 ms |
62164 KB |
Output is correct |
47 |
Correct |
181 ms |
60180 KB |
Output is correct |
48 |
Correct |
181 ms |
59576 KB |
Output is correct |
49 |
Correct |
71 ms |
31676 KB |
Output is correct |
50 |
Correct |
64 ms |
31800 KB |
Output is correct |
51 |
Correct |
133 ms |
50416 KB |
Output is correct |
52 |
Correct |
233 ms |
66268 KB |
Output is correct |
53 |
Correct |
229 ms |
64512 KB |
Output is correct |
54 |
Correct |
231 ms |
68788 KB |
Output is correct |
55 |
Correct |
155 ms |
61368 KB |
Output is correct |
56 |
Correct |
222 ms |
64304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
22928 KB |
Output is correct |
2 |
Correct |
12 ms |
22988 KB |
Output is correct |
3 |
Correct |
12 ms |
23004 KB |
Output is correct |
4 |
Correct |
12 ms |
23152 KB |
Output is correct |
5 |
Correct |
13 ms |
23324 KB |
Output is correct |
6 |
Correct |
12 ms |
23260 KB |
Output is correct |
7 |
Correct |
13 ms |
23332 KB |
Output is correct |
8 |
Correct |
13 ms |
23372 KB |
Output is correct |
9 |
Correct |
157 ms |
53800 KB |
Output is correct |
10 |
Correct |
204 ms |
60224 KB |
Output is correct |
11 |
Correct |
185 ms |
59656 KB |
Output is correct |
12 |
Correct |
194 ms |
62124 KB |
Output is correct |
13 |
Correct |
169 ms |
61368 KB |
Output is correct |
14 |
Correct |
146 ms |
55628 KB |
Output is correct |
15 |
Correct |
232 ms |
67220 KB |
Output is correct |
16 |
Correct |
228 ms |
65940 KB |
Output is correct |
17 |
Correct |
256 ms |
68608 KB |
Output is correct |
18 |
Correct |
212 ms |
66684 KB |
Output is correct |
19 |
Correct |
212 ms |
58588 KB |
Output is correct |
20 |
Correct |
225 ms |
64120 KB |
Output is correct |
21 |
Correct |
223 ms |
63184 KB |
Output is correct |
22 |
Correct |
224 ms |
63868 KB |
Output is correct |
23 |
Correct |
224 ms |
63692 KB |
Output is correct |
24 |
Correct |
242 ms |
62184 KB |
Output is correct |
25 |
Correct |
218 ms |
63332 KB |
Output is correct |
26 |
Correct |
215 ms |
61812 KB |
Output is correct |
27 |
Correct |
13 ms |
23248 KB |
Output is correct |
28 |
Correct |
12 ms |
23372 KB |
Output is correct |
29 |
Correct |
12 ms |
23344 KB |
Output is correct |
30 |
Correct |
12 ms |
23244 KB |
Output is correct |
31 |
Correct |
12 ms |
23268 KB |
Output is correct |
32 |
Correct |
13 ms |
23344 KB |
Output is correct |
33 |
Correct |
13 ms |
23372 KB |
Output is correct |
34 |
Correct |
12 ms |
23344 KB |
Output is correct |
35 |
Correct |
13 ms |
23244 KB |
Output is correct |
36 |
Correct |
26 ms |
27884 KB |
Output is correct |
37 |
Correct |
189 ms |
62444 KB |
Output is correct |
38 |
Correct |
206 ms |
62264 KB |
Output is correct |
39 |
Correct |
188 ms |
61112 KB |
Output is correct |
40 |
Correct |
186 ms |
59920 KB |
Output is correct |
41 |
Correct |
192 ms |
59124 KB |
Output is correct |
42 |
Correct |
154 ms |
55736 KB |
Output is correct |
43 |
Correct |
188 ms |
63684 KB |
Output is correct |
44 |
Correct |
198 ms |
63896 KB |
Output is correct |
45 |
Correct |
154 ms |
60940 KB |
Output is correct |
46 |
Correct |
181 ms |
59648 KB |
Output is correct |
47 |
Correct |
34 ms |
28036 KB |
Output is correct |
48 |
Correct |
309 ms |
67964 KB |
Output is correct |
49 |
Correct |
319 ms |
66692 KB |
Output is correct |
50 |
Correct |
328 ms |
65928 KB |
Output is correct |
51 |
Correct |
315 ms |
65068 KB |
Output is correct |
52 |
Correct |
303 ms |
62456 KB |
Output is correct |
53 |
Correct |
269 ms |
53036 KB |
Output is correct |
54 |
Correct |
312 ms |
69228 KB |
Output is correct |
55 |
Correct |
328 ms |
68984 KB |
Output is correct |
56 |
Correct |
372 ms |
66072 KB |
Output is correct |
57 |
Correct |
321 ms |
65060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
22988 KB |
Output is correct |
2 |
Correct |
12 ms |
22928 KB |
Output is correct |
3 |
Correct |
12 ms |
22988 KB |
Output is correct |
4 |
Correct |
12 ms |
23004 KB |
Output is correct |
5 |
Correct |
12 ms |
23152 KB |
Output is correct |
6 |
Correct |
13 ms |
23324 KB |
Output is correct |
7 |
Correct |
12 ms |
23260 KB |
Output is correct |
8 |
Correct |
13 ms |
23332 KB |
Output is correct |
9 |
Correct |
13 ms |
23372 KB |
Output is correct |
10 |
Correct |
157 ms |
53800 KB |
Output is correct |
11 |
Correct |
204 ms |
60224 KB |
Output is correct |
12 |
Correct |
185 ms |
59656 KB |
Output is correct |
13 |
Correct |
194 ms |
62124 KB |
Output is correct |
14 |
Correct |
169 ms |
61368 KB |
Output is correct |
15 |
Correct |
146 ms |
55628 KB |
Output is correct |
16 |
Correct |
232 ms |
67220 KB |
Output is correct |
17 |
Correct |
228 ms |
65940 KB |
Output is correct |
18 |
Correct |
256 ms |
68608 KB |
Output is correct |
19 |
Correct |
212 ms |
66684 KB |
Output is correct |
20 |
Correct |
212 ms |
58588 KB |
Output is correct |
21 |
Correct |
225 ms |
64120 KB |
Output is correct |
22 |
Correct |
223 ms |
63184 KB |
Output is correct |
23 |
Correct |
224 ms |
63868 KB |
Output is correct |
24 |
Correct |
224 ms |
63692 KB |
Output is correct |
25 |
Correct |
242 ms |
62184 KB |
Output is correct |
26 |
Correct |
218 ms |
63332 KB |
Output is correct |
27 |
Correct |
215 ms |
61812 KB |
Output is correct |
28 |
Correct |
13 ms |
23248 KB |
Output is correct |
29 |
Correct |
12 ms |
23372 KB |
Output is correct |
30 |
Correct |
12 ms |
23344 KB |
Output is correct |
31 |
Correct |
12 ms |
23244 KB |
Output is correct |
32 |
Correct |
12 ms |
23268 KB |
Output is correct |
33 |
Correct |
13 ms |
23344 KB |
Output is correct |
34 |
Correct |
13 ms |
23372 KB |
Output is correct |
35 |
Correct |
12 ms |
23344 KB |
Output is correct |
36 |
Correct |
13 ms |
23244 KB |
Output is correct |
37 |
Correct |
26 ms |
27884 KB |
Output is correct |
38 |
Correct |
189 ms |
62444 KB |
Output is correct |
39 |
Correct |
206 ms |
62264 KB |
Output is correct |
40 |
Correct |
188 ms |
61112 KB |
Output is correct |
41 |
Correct |
186 ms |
59920 KB |
Output is correct |
42 |
Correct |
192 ms |
59124 KB |
Output is correct |
43 |
Correct |
154 ms |
55736 KB |
Output is correct |
44 |
Correct |
188 ms |
63684 KB |
Output is correct |
45 |
Correct |
198 ms |
63896 KB |
Output is correct |
46 |
Correct |
154 ms |
60940 KB |
Output is correct |
47 |
Correct |
181 ms |
59648 KB |
Output is correct |
48 |
Correct |
34 ms |
28036 KB |
Output is correct |
49 |
Correct |
309 ms |
67964 KB |
Output is correct |
50 |
Correct |
319 ms |
66692 KB |
Output is correct |
51 |
Correct |
328 ms |
65928 KB |
Output is correct |
52 |
Correct |
315 ms |
65068 KB |
Output is correct |
53 |
Correct |
303 ms |
62456 KB |
Output is correct |
54 |
Correct |
269 ms |
53036 KB |
Output is correct |
55 |
Correct |
312 ms |
69228 KB |
Output is correct |
56 |
Correct |
328 ms |
68984 KB |
Output is correct |
57 |
Correct |
372 ms |
66072 KB |
Output is correct |
58 |
Correct |
321 ms |
65060 KB |
Output is correct |
59 |
Correct |
96 ms |
34436 KB |
Output is correct |
60 |
Correct |
322 ms |
68048 KB |
Output is correct |
61 |
Correct |
296 ms |
67116 KB |
Output is correct |
62 |
Correct |
326 ms |
69916 KB |
Output is correct |
63 |
Correct |
412 ms |
67744 KB |
Output is correct |
64 |
Correct |
12 ms |
23244 KB |
Output is correct |
65 |
Correct |
13 ms |
23340 KB |
Output is correct |
66 |
Correct |
13 ms |
23320 KB |
Output is correct |
67 |
Correct |
13 ms |
23108 KB |
Output is correct |
68 |
Correct |
12 ms |
23208 KB |
Output is correct |
69 |
Correct |
13 ms |
23412 KB |
Output is correct |
70 |
Correct |
13 ms |
23340 KB |
Output is correct |
71 |
Correct |
14 ms |
23340 KB |
Output is correct |
72 |
Correct |
12 ms |
23332 KB |
Output is correct |
73 |
Correct |
13 ms |
23372 KB |
Output is correct |
74 |
Correct |
168 ms |
56140 KB |
Output is correct |
75 |
Correct |
188 ms |
62164 KB |
Output is correct |
76 |
Correct |
181 ms |
60180 KB |
Output is correct |
77 |
Correct |
181 ms |
59576 KB |
Output is correct |
78 |
Correct |
71 ms |
31676 KB |
Output is correct |
79 |
Correct |
64 ms |
31800 KB |
Output is correct |
80 |
Correct |
133 ms |
50416 KB |
Output is correct |
81 |
Correct |
233 ms |
66268 KB |
Output is correct |
82 |
Correct |
229 ms |
64512 KB |
Output is correct |
83 |
Correct |
231 ms |
68788 KB |
Output is correct |
84 |
Correct |
155 ms |
61368 KB |
Output is correct |
85 |
Correct |
222 ms |
64304 KB |
Output is correct |
86 |
Correct |
89 ms |
36620 KB |
Output is correct |
87 |
Correct |
332 ms |
66588 KB |
Output is correct |
88 |
Correct |
320 ms |
66304 KB |
Output is correct |
89 |
Correct |
344 ms |
62288 KB |
Output is correct |
90 |
Correct |
164 ms |
36236 KB |
Output is correct |
91 |
Correct |
181 ms |
39044 KB |
Output is correct |
92 |
Correct |
287 ms |
55280 KB |
Output is correct |
93 |
Correct |
350 ms |
70288 KB |
Output is correct |
94 |
Correct |
400 ms |
69100 KB |
Output is correct |
95 |
Correct |
360 ms |
73096 KB |
Output is correct |
96 |
Correct |
407 ms |
65496 KB |
Output is correct |
97 |
Correct |
377 ms |
67216 KB |
Output is correct |