#include "swap.h"
#include<bits/stdc++.h>
using namespace std;
struct yal{
int u,v,w,vas;
bool operator <(yal b){
return w<b.w;
}
int getad(int fu){
return (fu^u^v);
}
};
const int maxn=100000+10,lg=17;
int n,m,wlca[lg][maxn],lca[lg][maxn],inf=1e9+5,mainres[maxn],timea;
vector<yal>alle;
vector<int>adjt[maxn];
pair<int,int>stf[maxn];
bool zird(int u,int v){
return stf[v].first<=stf[u].first&&stf[v].second>=stf[u].second;
}
struct dsu{
int par[maxn],val[maxn];
vector<int>allv[maxn];
dsu(){
for(int i=0;i<maxn;i++){
par[i]=i;
val[i]=inf;
allv[i].push_back(i);
}
};
int root(int u){
if(u==par[u]){
return u;
}
return par[u]=root(par[u]);
}
int con(int u,int v,int w){
int rootu=root(u),rootv=root(v);
if(rootu!=rootv){
par[rootv]=rootu;
if((int)allv[rootu].size()<(int)allv[rootv].size()){
swap(allv[rootu],allv[rootv]);
}
for(auto x:allv[rootv]){
allv[rootu].push_back(x);
}
if(val[rootu]<inf||val[rootv]<inf){
val[rootu]=w;
}
if(val[rootu]<inf){
for(auto x:allv[rootu]){
mainres[x]=min(mainres[x],val[rootu]);
}
allv[rootu].clear();
}
return 1;
}else{
return 0;
}
}
void tagh(int u,int w){
u=root(u);
for(auto x:allv[u]){
mainres[x]=min(mainres[x],w);
}
allv[u].clear();
val[u]=min(w,val[u]);
}
}ds;
int av=inf;
void dfs(int u=1,int par=-1){
timea++;
stf[u].first=timea;
for(auto x:adjt[u]){
int v=alle[x].getad(u);
if(v==par){
continue;
}
wlca[0][v]=alle[x].w;
lca[0][v]=u;
dfs(v,u);
}
stf[u].second=timea;
}
void callca(){
for(int i=1;i<lg;i++){
for(int j=1;j<=n;j++){
lca[i][j]=lca[i-1][lca[i-1][j]];
wlca[i][j]=max(wlca[i-1][j],wlca[i-1][lca[i-1][j]]);
}
}
}
int getlca(int u,int v){
if(zird(u,v)){
return v;
}
if(zird(v,u)){
return u;
}
for(int i=lg-1;i>=0;i--){
if(lca[i][u]!=0&&zird(v,lca[i][u])==0){
u=lca[i][u];
}
}
return lca[0][u];
}
int getwlca(int u,int v){
if(u==v){
return 0;
}
int ret=0;
for(int i=lg-1;i>=0;i--){
if(lca[i][u]!=0&&zird(v,lca[i][u])==0){
ret=max(ret,wlca[i][u]);
u=lca[i][u];
}
}
ret=max(ret,wlca[0][u]);
return ret;
}
void init(int N, int M,std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n=N;
m=M;
alle.resize(m);
for(int i=0;i<maxn;i++){
mainres[i]=inf;
}
for(int i=0;i<m;i++){
U[i]++;
V[i]++;
alle[i].u=U[i];
alle[i].v=V[i];
alle[i].w=W[i];
}
sort(alle.begin(),alle.end());
for(int i=0;i<m;i++){
if(ds.con(alle[i].u,alle[i].v,alle[i].w)){
alle[i].vas=1;
adjt[alle[i].u].push_back(i);
adjt[alle[i].v].push_back(i);
if((int)adjt[alle[i].u].size()>2||(int)adjt[alle[i].v].size()>2){
ds.tagh(alle[i].u,alle[i].w);
}
}else{
ds.tagh(alle[i].u,alle[i].w);
}
}
dfs();
callca();
}
int mx;
void dfsres(int u,int v){
int uv=getlca(u,v);
mx=max(getwlca(u,uv),getwlca(v,uv));
}
int getMinimumFuelCapacity(int X, int Y) {
X++;
Y++;
mx=inf;
dfsres(X,Y);
long long ret=max(mx,min(mainres[X],mainres[Y]));
if(ret>=inf){
return -1;
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
22104 KB |
Output is correct |
2 |
Correct |
6 ms |
22356 KB |
Output is correct |
3 |
Correct |
7 ms |
22104 KB |
Output is correct |
4 |
Correct |
10 ms |
22360 KB |
Output is correct |
5 |
Correct |
8 ms |
22116 KB |
Output is correct |
6 |
Correct |
8 ms |
22108 KB |
Output is correct |
7 |
Correct |
7 ms |
22108 KB |
Output is correct |
8 |
Correct |
7 ms |
22364 KB |
Output is correct |
9 |
Correct |
62 ms |
34184 KB |
Output is correct |
10 |
Correct |
87 ms |
37776 KB |
Output is correct |
11 |
Correct |
79 ms |
37140 KB |
Output is correct |
12 |
Correct |
93 ms |
38424 KB |
Output is correct |
13 |
Correct |
72 ms |
37120 KB |
Output is correct |
14 |
Correct |
78 ms |
33996 KB |
Output is correct |
15 |
Correct |
243 ms |
39796 KB |
Output is correct |
16 |
Correct |
213 ms |
38072 KB |
Output is correct |
17 |
Correct |
211 ms |
41776 KB |
Output is correct |
18 |
Correct |
211 ms |
37812 KB |
Output is correct |
19 |
Correct |
92 ms |
28320 KB |
Output is correct |
20 |
Correct |
233 ms |
40184 KB |
Output is correct |
21 |
Correct |
229 ms |
39432 KB |
Output is correct |
22 |
Correct |
240 ms |
41264 KB |
Output is correct |
23 |
Correct |
212 ms |
38816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
22104 KB |
Output is correct |
2 |
Correct |
6 ms |
22356 KB |
Output is correct |
3 |
Correct |
114 ms |
33392 KB |
Output is correct |
4 |
Correct |
115 ms |
33576 KB |
Output is correct |
5 |
Correct |
118 ms |
33636 KB |
Output is correct |
6 |
Correct |
115 ms |
33584 KB |
Output is correct |
7 |
Correct |
121 ms |
33688 KB |
Output is correct |
8 |
Correct |
127 ms |
33288 KB |
Output is correct |
9 |
Correct |
114 ms |
33676 KB |
Output is correct |
10 |
Correct |
112 ms |
33344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
22104 KB |
Output is correct |
2 |
Correct |
6 ms |
22356 KB |
Output is correct |
3 |
Correct |
7 ms |
22104 KB |
Output is correct |
4 |
Correct |
10 ms |
22360 KB |
Output is correct |
5 |
Correct |
8 ms |
22116 KB |
Output is correct |
6 |
Correct |
8 ms |
22108 KB |
Output is correct |
7 |
Correct |
7 ms |
22108 KB |
Output is correct |
8 |
Correct |
7 ms |
22364 KB |
Output is correct |
9 |
Correct |
10 ms |
22108 KB |
Output is correct |
10 |
Correct |
8 ms |
22264 KB |
Output is correct |
11 |
Correct |
7 ms |
22108 KB |
Output is correct |
12 |
Correct |
9 ms |
22280 KB |
Output is correct |
13 |
Correct |
7 ms |
22108 KB |
Output is correct |
14 |
Correct |
7 ms |
22260 KB |
Output is correct |
15 |
Correct |
7 ms |
22312 KB |
Output is correct |
16 |
Correct |
8 ms |
22108 KB |
Output is correct |
17 |
Correct |
7 ms |
22108 KB |
Output is correct |
18 |
Correct |
8 ms |
22308 KB |
Output is correct |
19 |
Correct |
8 ms |
22108 KB |
Output is correct |
20 |
Correct |
7 ms |
22224 KB |
Output is correct |
21 |
Correct |
7 ms |
22108 KB |
Output is correct |
22 |
Correct |
7 ms |
22256 KB |
Output is correct |
23 |
Correct |
7 ms |
22108 KB |
Output is correct |
24 |
Correct |
8 ms |
22288 KB |
Output is correct |
25 |
Correct |
7 ms |
22108 KB |
Output is correct |
26 |
Correct |
9 ms |
22360 KB |
Output is correct |
27 |
Correct |
7 ms |
22360 KB |
Output is correct |
28 |
Correct |
8 ms |
22300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
22108 KB |
Output is correct |
2 |
Correct |
16 ms |
22104 KB |
Output is correct |
3 |
Correct |
6 ms |
22356 KB |
Output is correct |
4 |
Correct |
7 ms |
22104 KB |
Output is correct |
5 |
Correct |
10 ms |
22360 KB |
Output is correct |
6 |
Correct |
8 ms |
22116 KB |
Output is correct |
7 |
Correct |
8 ms |
22108 KB |
Output is correct |
8 |
Correct |
7 ms |
22108 KB |
Output is correct |
9 |
Correct |
7 ms |
22364 KB |
Output is correct |
10 |
Correct |
62 ms |
34184 KB |
Output is correct |
11 |
Correct |
87 ms |
37776 KB |
Output is correct |
12 |
Correct |
79 ms |
37140 KB |
Output is correct |
13 |
Correct |
93 ms |
38424 KB |
Output is correct |
14 |
Correct |
72 ms |
37120 KB |
Output is correct |
15 |
Correct |
8 ms |
22264 KB |
Output is correct |
16 |
Correct |
7 ms |
22108 KB |
Output is correct |
17 |
Correct |
9 ms |
22280 KB |
Output is correct |
18 |
Correct |
7 ms |
22108 KB |
Output is correct |
19 |
Correct |
7 ms |
22260 KB |
Output is correct |
20 |
Correct |
7 ms |
22312 KB |
Output is correct |
21 |
Correct |
8 ms |
22108 KB |
Output is correct |
22 |
Correct |
7 ms |
22108 KB |
Output is correct |
23 |
Correct |
8 ms |
22308 KB |
Output is correct |
24 |
Correct |
8 ms |
22108 KB |
Output is correct |
25 |
Correct |
7 ms |
22224 KB |
Output is correct |
26 |
Correct |
7 ms |
22108 KB |
Output is correct |
27 |
Correct |
7 ms |
22256 KB |
Output is correct |
28 |
Correct |
7 ms |
22108 KB |
Output is correct |
29 |
Correct |
8 ms |
22288 KB |
Output is correct |
30 |
Correct |
7 ms |
22108 KB |
Output is correct |
31 |
Correct |
9 ms |
22360 KB |
Output is correct |
32 |
Correct |
7 ms |
22360 KB |
Output is correct |
33 |
Correct |
8 ms |
22300 KB |
Output is correct |
34 |
Correct |
13 ms |
23128 KB |
Output is correct |
35 |
Correct |
85 ms |
37460 KB |
Output is correct |
36 |
Correct |
93 ms |
34780 KB |
Output is correct |
37 |
Correct |
84 ms |
32592 KB |
Output is correct |
38 |
Correct |
79 ms |
31568 KB |
Output is correct |
39 |
Correct |
82 ms |
30656 KB |
Output is correct |
40 |
Correct |
67 ms |
29780 KB |
Output is correct |
41 |
Correct |
101 ms |
36332 KB |
Output is correct |
42 |
Correct |
81 ms |
37416 KB |
Output is correct |
43 |
Correct |
88 ms |
35320 KB |
Output is correct |
44 |
Correct |
74 ms |
30712 KB |
Output is correct |
45 |
Correct |
86 ms |
31572 KB |
Output is correct |
46 |
Correct |
85 ms |
34144 KB |
Output is correct |
47 |
Correct |
75 ms |
31304 KB |
Output is correct |
48 |
Correct |
75 ms |
31056 KB |
Output is correct |
49 |
Correct |
51 ms |
28384 KB |
Output is correct |
50 |
Correct |
44 ms |
27204 KB |
Output is correct |
51 |
Correct |
79 ms |
30096 KB |
Output is correct |
52 |
Correct |
103 ms |
36536 KB |
Output is correct |
53 |
Correct |
101 ms |
33680 KB |
Output is correct |
54 |
Correct |
116 ms |
40388 KB |
Output is correct |
55 |
Correct |
65 ms |
36348 KB |
Output is correct |
56 |
Correct |
95 ms |
33360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
22104 KB |
Output is correct |
2 |
Correct |
6 ms |
22356 KB |
Output is correct |
3 |
Correct |
7 ms |
22104 KB |
Output is correct |
4 |
Correct |
10 ms |
22360 KB |
Output is correct |
5 |
Correct |
8 ms |
22116 KB |
Output is correct |
6 |
Correct |
8 ms |
22108 KB |
Output is correct |
7 |
Correct |
7 ms |
22108 KB |
Output is correct |
8 |
Correct |
7 ms |
22364 KB |
Output is correct |
9 |
Correct |
62 ms |
34184 KB |
Output is correct |
10 |
Correct |
87 ms |
37776 KB |
Output is correct |
11 |
Correct |
79 ms |
37140 KB |
Output is correct |
12 |
Correct |
93 ms |
38424 KB |
Output is correct |
13 |
Correct |
72 ms |
37120 KB |
Output is correct |
14 |
Correct |
78 ms |
33996 KB |
Output is correct |
15 |
Correct |
243 ms |
39796 KB |
Output is correct |
16 |
Correct |
213 ms |
38072 KB |
Output is correct |
17 |
Correct |
211 ms |
41776 KB |
Output is correct |
18 |
Correct |
211 ms |
37812 KB |
Output is correct |
19 |
Correct |
114 ms |
33392 KB |
Output is correct |
20 |
Correct |
115 ms |
33576 KB |
Output is correct |
21 |
Correct |
118 ms |
33636 KB |
Output is correct |
22 |
Correct |
115 ms |
33584 KB |
Output is correct |
23 |
Correct |
121 ms |
33688 KB |
Output is correct |
24 |
Correct |
127 ms |
33288 KB |
Output is correct |
25 |
Correct |
114 ms |
33676 KB |
Output is correct |
26 |
Correct |
112 ms |
33344 KB |
Output is correct |
27 |
Correct |
8 ms |
22264 KB |
Output is correct |
28 |
Correct |
7 ms |
22108 KB |
Output is correct |
29 |
Correct |
9 ms |
22280 KB |
Output is correct |
30 |
Correct |
7 ms |
22108 KB |
Output is correct |
31 |
Correct |
7 ms |
22260 KB |
Output is correct |
32 |
Correct |
7 ms |
22312 KB |
Output is correct |
33 |
Correct |
8 ms |
22108 KB |
Output is correct |
34 |
Correct |
7 ms |
22108 KB |
Output is correct |
35 |
Correct |
8 ms |
22308 KB |
Output is correct |
36 |
Correct |
13 ms |
23128 KB |
Output is correct |
37 |
Correct |
85 ms |
37460 KB |
Output is correct |
38 |
Correct |
93 ms |
34780 KB |
Output is correct |
39 |
Correct |
84 ms |
32592 KB |
Output is correct |
40 |
Correct |
79 ms |
31568 KB |
Output is correct |
41 |
Correct |
82 ms |
30656 KB |
Output is correct |
42 |
Correct |
67 ms |
29780 KB |
Output is correct |
43 |
Correct |
101 ms |
36332 KB |
Output is correct |
44 |
Correct |
81 ms |
37416 KB |
Output is correct |
45 |
Correct |
88 ms |
35320 KB |
Output is correct |
46 |
Correct |
74 ms |
30712 KB |
Output is correct |
47 |
Correct |
24 ms |
23640 KB |
Output is correct |
48 |
Correct |
224 ms |
38740 KB |
Output is correct |
49 |
Correct |
268 ms |
36560 KB |
Output is correct |
50 |
Correct |
236 ms |
35536 KB |
Output is correct |
51 |
Correct |
248 ms |
34512 KB |
Output is correct |
52 |
Correct |
197 ms |
32944 KB |
Output is correct |
53 |
Correct |
157 ms |
31304 KB |
Output is correct |
54 |
Correct |
261 ms |
39044 KB |
Output is correct |
55 |
Correct |
262 ms |
39596 KB |
Output is correct |
56 |
Correct |
217 ms |
38368 KB |
Output is correct |
57 |
Correct |
210 ms |
33964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
22108 KB |
Output is correct |
2 |
Correct |
16 ms |
22104 KB |
Output is correct |
3 |
Correct |
6 ms |
22356 KB |
Output is correct |
4 |
Correct |
7 ms |
22104 KB |
Output is correct |
5 |
Correct |
10 ms |
22360 KB |
Output is correct |
6 |
Correct |
8 ms |
22116 KB |
Output is correct |
7 |
Correct |
8 ms |
22108 KB |
Output is correct |
8 |
Correct |
7 ms |
22108 KB |
Output is correct |
9 |
Correct |
7 ms |
22364 KB |
Output is correct |
10 |
Correct |
62 ms |
34184 KB |
Output is correct |
11 |
Correct |
87 ms |
37776 KB |
Output is correct |
12 |
Correct |
79 ms |
37140 KB |
Output is correct |
13 |
Correct |
93 ms |
38424 KB |
Output is correct |
14 |
Correct |
72 ms |
37120 KB |
Output is correct |
15 |
Correct |
78 ms |
33996 KB |
Output is correct |
16 |
Correct |
243 ms |
39796 KB |
Output is correct |
17 |
Correct |
213 ms |
38072 KB |
Output is correct |
18 |
Correct |
211 ms |
41776 KB |
Output is correct |
19 |
Correct |
211 ms |
37812 KB |
Output is correct |
20 |
Correct |
114 ms |
33392 KB |
Output is correct |
21 |
Correct |
115 ms |
33576 KB |
Output is correct |
22 |
Correct |
118 ms |
33636 KB |
Output is correct |
23 |
Correct |
115 ms |
33584 KB |
Output is correct |
24 |
Correct |
121 ms |
33688 KB |
Output is correct |
25 |
Correct |
127 ms |
33288 KB |
Output is correct |
26 |
Correct |
114 ms |
33676 KB |
Output is correct |
27 |
Correct |
112 ms |
33344 KB |
Output is correct |
28 |
Correct |
8 ms |
22264 KB |
Output is correct |
29 |
Correct |
7 ms |
22108 KB |
Output is correct |
30 |
Correct |
9 ms |
22280 KB |
Output is correct |
31 |
Correct |
7 ms |
22108 KB |
Output is correct |
32 |
Correct |
7 ms |
22260 KB |
Output is correct |
33 |
Correct |
7 ms |
22312 KB |
Output is correct |
34 |
Correct |
8 ms |
22108 KB |
Output is correct |
35 |
Correct |
7 ms |
22108 KB |
Output is correct |
36 |
Correct |
8 ms |
22308 KB |
Output is correct |
37 |
Correct |
13 ms |
23128 KB |
Output is correct |
38 |
Correct |
85 ms |
37460 KB |
Output is correct |
39 |
Correct |
93 ms |
34780 KB |
Output is correct |
40 |
Correct |
84 ms |
32592 KB |
Output is correct |
41 |
Correct |
79 ms |
31568 KB |
Output is correct |
42 |
Correct |
82 ms |
30656 KB |
Output is correct |
43 |
Correct |
67 ms |
29780 KB |
Output is correct |
44 |
Correct |
101 ms |
36332 KB |
Output is correct |
45 |
Correct |
81 ms |
37416 KB |
Output is correct |
46 |
Correct |
88 ms |
35320 KB |
Output is correct |
47 |
Correct |
74 ms |
30712 KB |
Output is correct |
48 |
Correct |
24 ms |
23640 KB |
Output is correct |
49 |
Correct |
224 ms |
38740 KB |
Output is correct |
50 |
Correct |
268 ms |
36560 KB |
Output is correct |
51 |
Correct |
236 ms |
35536 KB |
Output is correct |
52 |
Correct |
248 ms |
34512 KB |
Output is correct |
53 |
Correct |
197 ms |
32944 KB |
Output is correct |
54 |
Correct |
157 ms |
31304 KB |
Output is correct |
55 |
Correct |
261 ms |
39044 KB |
Output is correct |
56 |
Correct |
262 ms |
39596 KB |
Output is correct |
57 |
Correct |
217 ms |
38368 KB |
Output is correct |
58 |
Correct |
210 ms |
33964 KB |
Output is correct |
59 |
Correct |
92 ms |
28320 KB |
Output is correct |
60 |
Correct |
233 ms |
40184 KB |
Output is correct |
61 |
Correct |
229 ms |
39432 KB |
Output is correct |
62 |
Correct |
240 ms |
41264 KB |
Output is correct |
63 |
Correct |
212 ms |
38816 KB |
Output is correct |
64 |
Correct |
8 ms |
22108 KB |
Output is correct |
65 |
Correct |
7 ms |
22224 KB |
Output is correct |
66 |
Correct |
7 ms |
22108 KB |
Output is correct |
67 |
Correct |
7 ms |
22256 KB |
Output is correct |
68 |
Correct |
7 ms |
22108 KB |
Output is correct |
69 |
Correct |
8 ms |
22288 KB |
Output is correct |
70 |
Correct |
7 ms |
22108 KB |
Output is correct |
71 |
Correct |
9 ms |
22360 KB |
Output is correct |
72 |
Correct |
7 ms |
22360 KB |
Output is correct |
73 |
Correct |
8 ms |
22300 KB |
Output is correct |
74 |
Correct |
86 ms |
31572 KB |
Output is correct |
75 |
Correct |
85 ms |
34144 KB |
Output is correct |
76 |
Correct |
75 ms |
31304 KB |
Output is correct |
77 |
Correct |
75 ms |
31056 KB |
Output is correct |
78 |
Correct |
51 ms |
28384 KB |
Output is correct |
79 |
Correct |
44 ms |
27204 KB |
Output is correct |
80 |
Correct |
79 ms |
30096 KB |
Output is correct |
81 |
Correct |
103 ms |
36536 KB |
Output is correct |
82 |
Correct |
101 ms |
33680 KB |
Output is correct |
83 |
Correct |
116 ms |
40388 KB |
Output is correct |
84 |
Correct |
65 ms |
36348 KB |
Output is correct |
85 |
Correct |
95 ms |
33360 KB |
Output is correct |
86 |
Correct |
54 ms |
25940 KB |
Output is correct |
87 |
Correct |
276 ms |
36052 KB |
Output is correct |
88 |
Correct |
242 ms |
36024 KB |
Output is correct |
89 |
Correct |
167 ms |
32884 KB |
Output is correct |
90 |
Correct |
161 ms |
30756 KB |
Output is correct |
91 |
Correct |
140 ms |
30896 KB |
Output is correct |
92 |
Correct |
182 ms |
32692 KB |
Output is correct |
93 |
Correct |
297 ms |
38928 KB |
Output is correct |
94 |
Correct |
206 ms |
35896 KB |
Output is correct |
95 |
Correct |
303 ms |
41836 KB |
Output is correct |
96 |
Correct |
215 ms |
36724 KB |
Output is correct |
97 |
Correct |
224 ms |
34668 KB |
Output is correct |