// Code by Parsa Eslami
#include "swap.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bit(i,j) ((j>>i)&1)
#define minm(x,y) x=min(x,y)
#define maxm(x,y) x=max(x,y)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define S second
#define F first
#define pb push_back
#define SZ(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define err(x) cout<<#x<<": "<<x<<'\n'
#define wtf cout<<"WHAT THE FUCK!\n"
#define dmid int mid=(r+l)/2
#define lc 2*id
#define rc 2*id+1
using namespace std;
const int N=1e5+4;
int D1[N],ans[N],mx[N],dsu[N],D[N];
vector<int> x[N];
vector<pii> vc[N];
int root(int v){
if(dsu[v]<0) return v;
return (dsu[v]=root(dsu[v]));
}
void join(int u,int v,int tme){
D[u]++;
D[v]++;
int z=0;
if(D[u]==2) z--;
else if(D[u]==1) z++;
if(D[v]==2) z--;
else if(D[v]==1) z++;
int mxx=0;
mxx=max(D[u],D[v]);
u=root(u); v=root(v);
if(u!=v){
if(ans[v]&&ans[u]==0){
for(int v0:x[u]) ans[v0]=tme;
}
if(ans[u]&&ans[v]==0){
for(int v0:x[v]) ans[v0]=tme;
}
if(SZ(x[u])>SZ(x[v])) swap(u,v);
for(int v0:x[u]){
x[v].pb(v0);
vc[v0].pb({tme,v});
}
dsu[v]+=dsu[u]; dsu[u]=v;
}
if(u!=v) D1[v]=D1[u]+D1[v]+z;
else D1[v]+=z;
mx[v]=max(max(mx[v],mx[u]),mxx);
if((mx[v]>=3||D1[v]==0)&&ans[v]==0){
for(int v0:x[v]) ans[v0]=tme;
}
}
int TIME(int u,int v){
int pu=0;
int numu=u;
int numv=v;
int pv=0;
int rt=0;
while(numu!=numv){
int tmeu=1e9;
int tmev=1e9;
if(pu<SZ(vc[u])) tmeu=vc[u][pu].F;
if(pv<SZ(vc[v])) tmev=vc[v][pv].F;
if(tmeu<tmev){
rt=tmeu;
numu=vc[u][pu].S;
pu++;
}
if(tmev<=tmeu){
rt=tmev;
numv=vc[v][pv].S;
pv++;
}
}
return rt;
}
void init(int n,int m,vector<int> u,vector<int> v,vector<int> w){
FOR(i,0,N-1) dsu[i]=-1,x[i].pb(i);
vector<pair<int,pii>> vcc;
FOR(i,0,m-1) vcc.pb({w[i],{u[i],v[i]}});
sort(all(vcc));
FOR(i,0,m-1) join(vcc[i].S.F,vcc[i].S.S,vcc[i].F);
}
int getMinimumFuelCapacity(int x,int y){
if(ans[x]==0||ans[y]==0) return -1;
int rt=max(max(ans[x],ans[y]),TIME(x,y));
return rt;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
8532 KB |
Output is correct |
2 |
Correct |
10 ms |
8532 KB |
Output is correct |
3 |
Correct |
8 ms |
8532 KB |
Output is correct |
4 |
Correct |
7 ms |
8532 KB |
Output is correct |
5 |
Correct |
9 ms |
8608 KB |
Output is correct |
6 |
Correct |
8 ms |
8660 KB |
Output is correct |
7 |
Correct |
8 ms |
8604 KB |
Output is correct |
8 |
Correct |
7 ms |
8532 KB |
Output is correct |
9 |
Correct |
119 ms |
22456 KB |
Output is correct |
10 |
Correct |
179 ms |
25048 KB |
Output is correct |
11 |
Correct |
145 ms |
24848 KB |
Output is correct |
12 |
Correct |
160 ms |
25792 KB |
Output is correct |
13 |
Correct |
93 ms |
17136 KB |
Output is correct |
14 |
Correct |
117 ms |
22464 KB |
Output is correct |
15 |
Correct |
195 ms |
26940 KB |
Output is correct |
16 |
Correct |
220 ms |
26532 KB |
Output is correct |
17 |
Correct |
208 ms |
27648 KB |
Output is correct |
18 |
Correct |
131 ms |
18732 KB |
Output is correct |
19 |
Correct |
80 ms |
14944 KB |
Output is correct |
20 |
Correct |
237 ms |
27640 KB |
Output is correct |
21 |
Correct |
273 ms |
27392 KB |
Output is correct |
22 |
Correct |
248 ms |
28444 KB |
Output is correct |
23 |
Correct |
149 ms |
19476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
8532 KB |
Output is correct |
2 |
Correct |
10 ms |
8532 KB |
Output is correct |
3 |
Correct |
134 ms |
18540 KB |
Output is correct |
4 |
Correct |
134 ms |
18712 KB |
Output is correct |
5 |
Correct |
167 ms |
18812 KB |
Output is correct |
6 |
Correct |
130 ms |
18616 KB |
Output is correct |
7 |
Correct |
131 ms |
18884 KB |
Output is correct |
8 |
Correct |
136 ms |
18524 KB |
Output is correct |
9 |
Correct |
133 ms |
18704 KB |
Output is correct |
10 |
Correct |
127 ms |
18548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
8532 KB |
Output is correct |
2 |
Correct |
10 ms |
8532 KB |
Output is correct |
3 |
Correct |
8 ms |
8532 KB |
Output is correct |
4 |
Correct |
7 ms |
8532 KB |
Output is correct |
5 |
Correct |
9 ms |
8608 KB |
Output is correct |
6 |
Correct |
8 ms |
8660 KB |
Output is correct |
7 |
Correct |
8 ms |
8604 KB |
Output is correct |
8 |
Correct |
7 ms |
8532 KB |
Output is correct |
9 |
Correct |
7 ms |
8532 KB |
Output is correct |
10 |
Correct |
9 ms |
8620 KB |
Output is correct |
11 |
Correct |
11 ms |
8616 KB |
Output is correct |
12 |
Correct |
9 ms |
8660 KB |
Output is correct |
13 |
Correct |
8 ms |
8660 KB |
Output is correct |
14 |
Correct |
8 ms |
8644 KB |
Output is correct |
15 |
Correct |
8 ms |
8608 KB |
Output is correct |
16 |
Correct |
8 ms |
8660 KB |
Output is correct |
17 |
Correct |
8 ms |
8640 KB |
Output is correct |
18 |
Correct |
12 ms |
8660 KB |
Output is correct |
19 |
Correct |
8 ms |
8516 KB |
Output is correct |
20 |
Correct |
8 ms |
8604 KB |
Output is correct |
21 |
Correct |
8 ms |
8532 KB |
Output is correct |
22 |
Correct |
8 ms |
8600 KB |
Output is correct |
23 |
Correct |
8 ms |
8532 KB |
Output is correct |
24 |
Correct |
8 ms |
8604 KB |
Output is correct |
25 |
Correct |
8 ms |
8644 KB |
Output is correct |
26 |
Correct |
9 ms |
8660 KB |
Output is correct |
27 |
Correct |
8 ms |
8532 KB |
Output is correct |
28 |
Correct |
8 ms |
8660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8532 KB |
Output is correct |
2 |
Correct |
11 ms |
8532 KB |
Output is correct |
3 |
Correct |
10 ms |
8532 KB |
Output is correct |
4 |
Correct |
8 ms |
8532 KB |
Output is correct |
5 |
Correct |
7 ms |
8532 KB |
Output is correct |
6 |
Correct |
9 ms |
8608 KB |
Output is correct |
7 |
Correct |
8 ms |
8660 KB |
Output is correct |
8 |
Correct |
8 ms |
8604 KB |
Output is correct |
9 |
Correct |
7 ms |
8532 KB |
Output is correct |
10 |
Correct |
119 ms |
22456 KB |
Output is correct |
11 |
Correct |
179 ms |
25048 KB |
Output is correct |
12 |
Correct |
145 ms |
24848 KB |
Output is correct |
13 |
Correct |
160 ms |
25792 KB |
Output is correct |
14 |
Correct |
93 ms |
17136 KB |
Output is correct |
15 |
Correct |
9 ms |
8620 KB |
Output is correct |
16 |
Correct |
11 ms |
8616 KB |
Output is correct |
17 |
Correct |
9 ms |
8660 KB |
Output is correct |
18 |
Correct |
8 ms |
8660 KB |
Output is correct |
19 |
Correct |
8 ms |
8644 KB |
Output is correct |
20 |
Correct |
8 ms |
8608 KB |
Output is correct |
21 |
Correct |
8 ms |
8660 KB |
Output is correct |
22 |
Correct |
8 ms |
8640 KB |
Output is correct |
23 |
Correct |
12 ms |
8660 KB |
Output is correct |
24 |
Correct |
8 ms |
8516 KB |
Output is correct |
25 |
Correct |
8 ms |
8604 KB |
Output is correct |
26 |
Correct |
8 ms |
8532 KB |
Output is correct |
27 |
Correct |
8 ms |
8600 KB |
Output is correct |
28 |
Correct |
8 ms |
8532 KB |
Output is correct |
29 |
Correct |
8 ms |
8604 KB |
Output is correct |
30 |
Correct |
8 ms |
8644 KB |
Output is correct |
31 |
Correct |
9 ms |
8660 KB |
Output is correct |
32 |
Correct |
8 ms |
8532 KB |
Output is correct |
33 |
Correct |
8 ms |
8660 KB |
Output is correct |
34 |
Correct |
19 ms |
10552 KB |
Output is correct |
35 |
Correct |
156 ms |
26028 KB |
Output is correct |
36 |
Correct |
172 ms |
25784 KB |
Output is correct |
37 |
Correct |
148 ms |
25276 KB |
Output is correct |
38 |
Correct |
144 ms |
24260 KB |
Output is correct |
39 |
Correct |
156 ms |
23884 KB |
Output is correct |
40 |
Correct |
135 ms |
22012 KB |
Output is correct |
41 |
Correct |
152 ms |
26464 KB |
Output is correct |
42 |
Correct |
165 ms |
26312 KB |
Output is correct |
43 |
Correct |
92 ms |
18244 KB |
Output is correct |
44 |
Correct |
143 ms |
23264 KB |
Output is correct |
45 |
Correct |
107 ms |
19120 KB |
Output is correct |
46 |
Correct |
165 ms |
25832 KB |
Output is correct |
47 |
Correct |
147 ms |
21780 KB |
Output is correct |
48 |
Correct |
114 ms |
18924 KB |
Output is correct |
49 |
Correct |
66 ms |
16140 KB |
Output is correct |
50 |
Correct |
65 ms |
13836 KB |
Output is correct |
51 |
Correct |
89 ms |
17604 KB |
Output is correct |
52 |
Correct |
179 ms |
26956 KB |
Output is correct |
53 |
Correct |
155 ms |
22780 KB |
Output is correct |
54 |
Correct |
211 ms |
29876 KB |
Output is correct |
55 |
Correct |
84 ms |
18244 KB |
Output is correct |
56 |
Correct |
141 ms |
21388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
8532 KB |
Output is correct |
2 |
Correct |
10 ms |
8532 KB |
Output is correct |
3 |
Correct |
8 ms |
8532 KB |
Output is correct |
4 |
Correct |
7 ms |
8532 KB |
Output is correct |
5 |
Correct |
9 ms |
8608 KB |
Output is correct |
6 |
Correct |
8 ms |
8660 KB |
Output is correct |
7 |
Correct |
8 ms |
8604 KB |
Output is correct |
8 |
Correct |
7 ms |
8532 KB |
Output is correct |
9 |
Correct |
119 ms |
22456 KB |
Output is correct |
10 |
Correct |
179 ms |
25048 KB |
Output is correct |
11 |
Correct |
145 ms |
24848 KB |
Output is correct |
12 |
Correct |
160 ms |
25792 KB |
Output is correct |
13 |
Correct |
93 ms |
17136 KB |
Output is correct |
14 |
Correct |
117 ms |
22464 KB |
Output is correct |
15 |
Correct |
195 ms |
26940 KB |
Output is correct |
16 |
Correct |
220 ms |
26532 KB |
Output is correct |
17 |
Correct |
208 ms |
27648 KB |
Output is correct |
18 |
Correct |
131 ms |
18732 KB |
Output is correct |
19 |
Correct |
134 ms |
18540 KB |
Output is correct |
20 |
Correct |
134 ms |
18712 KB |
Output is correct |
21 |
Correct |
167 ms |
18812 KB |
Output is correct |
22 |
Correct |
130 ms |
18616 KB |
Output is correct |
23 |
Correct |
131 ms |
18884 KB |
Output is correct |
24 |
Correct |
136 ms |
18524 KB |
Output is correct |
25 |
Correct |
133 ms |
18704 KB |
Output is correct |
26 |
Correct |
127 ms |
18548 KB |
Output is correct |
27 |
Correct |
9 ms |
8620 KB |
Output is correct |
28 |
Correct |
11 ms |
8616 KB |
Output is correct |
29 |
Correct |
9 ms |
8660 KB |
Output is correct |
30 |
Correct |
8 ms |
8660 KB |
Output is correct |
31 |
Correct |
8 ms |
8644 KB |
Output is correct |
32 |
Correct |
8 ms |
8608 KB |
Output is correct |
33 |
Correct |
8 ms |
8660 KB |
Output is correct |
34 |
Correct |
8 ms |
8640 KB |
Output is correct |
35 |
Correct |
12 ms |
8660 KB |
Output is correct |
36 |
Correct |
19 ms |
10552 KB |
Output is correct |
37 |
Correct |
156 ms |
26028 KB |
Output is correct |
38 |
Correct |
172 ms |
25784 KB |
Output is correct |
39 |
Correct |
148 ms |
25276 KB |
Output is correct |
40 |
Correct |
144 ms |
24260 KB |
Output is correct |
41 |
Correct |
156 ms |
23884 KB |
Output is correct |
42 |
Correct |
135 ms |
22012 KB |
Output is correct |
43 |
Correct |
152 ms |
26464 KB |
Output is correct |
44 |
Correct |
165 ms |
26312 KB |
Output is correct |
45 |
Correct |
92 ms |
18244 KB |
Output is correct |
46 |
Correct |
143 ms |
23264 KB |
Output is correct |
47 |
Correct |
24 ms |
10804 KB |
Output is correct |
48 |
Correct |
252 ms |
27776 KB |
Output is correct |
49 |
Correct |
237 ms |
27196 KB |
Output is correct |
50 |
Correct |
313 ms |
26888 KB |
Output is correct |
51 |
Correct |
230 ms |
26212 KB |
Output is correct |
52 |
Correct |
207 ms |
24632 KB |
Output is correct |
53 |
Correct |
164 ms |
21180 KB |
Output is correct |
54 |
Correct |
263 ms |
27948 KB |
Output is correct |
55 |
Correct |
251 ms |
28140 KB |
Output is correct |
56 |
Correct |
165 ms |
19840 KB |
Output is correct |
57 |
Correct |
213 ms |
24904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8532 KB |
Output is correct |
2 |
Correct |
11 ms |
8532 KB |
Output is correct |
3 |
Correct |
10 ms |
8532 KB |
Output is correct |
4 |
Correct |
8 ms |
8532 KB |
Output is correct |
5 |
Correct |
7 ms |
8532 KB |
Output is correct |
6 |
Correct |
9 ms |
8608 KB |
Output is correct |
7 |
Correct |
8 ms |
8660 KB |
Output is correct |
8 |
Correct |
8 ms |
8604 KB |
Output is correct |
9 |
Correct |
7 ms |
8532 KB |
Output is correct |
10 |
Correct |
119 ms |
22456 KB |
Output is correct |
11 |
Correct |
179 ms |
25048 KB |
Output is correct |
12 |
Correct |
145 ms |
24848 KB |
Output is correct |
13 |
Correct |
160 ms |
25792 KB |
Output is correct |
14 |
Correct |
93 ms |
17136 KB |
Output is correct |
15 |
Correct |
117 ms |
22464 KB |
Output is correct |
16 |
Correct |
195 ms |
26940 KB |
Output is correct |
17 |
Correct |
220 ms |
26532 KB |
Output is correct |
18 |
Correct |
208 ms |
27648 KB |
Output is correct |
19 |
Correct |
131 ms |
18732 KB |
Output is correct |
20 |
Correct |
134 ms |
18540 KB |
Output is correct |
21 |
Correct |
134 ms |
18712 KB |
Output is correct |
22 |
Correct |
167 ms |
18812 KB |
Output is correct |
23 |
Correct |
130 ms |
18616 KB |
Output is correct |
24 |
Correct |
131 ms |
18884 KB |
Output is correct |
25 |
Correct |
136 ms |
18524 KB |
Output is correct |
26 |
Correct |
133 ms |
18704 KB |
Output is correct |
27 |
Correct |
127 ms |
18548 KB |
Output is correct |
28 |
Correct |
9 ms |
8620 KB |
Output is correct |
29 |
Correct |
11 ms |
8616 KB |
Output is correct |
30 |
Correct |
9 ms |
8660 KB |
Output is correct |
31 |
Correct |
8 ms |
8660 KB |
Output is correct |
32 |
Correct |
8 ms |
8644 KB |
Output is correct |
33 |
Correct |
8 ms |
8608 KB |
Output is correct |
34 |
Correct |
8 ms |
8660 KB |
Output is correct |
35 |
Correct |
8 ms |
8640 KB |
Output is correct |
36 |
Correct |
12 ms |
8660 KB |
Output is correct |
37 |
Correct |
19 ms |
10552 KB |
Output is correct |
38 |
Correct |
156 ms |
26028 KB |
Output is correct |
39 |
Correct |
172 ms |
25784 KB |
Output is correct |
40 |
Correct |
148 ms |
25276 KB |
Output is correct |
41 |
Correct |
144 ms |
24260 KB |
Output is correct |
42 |
Correct |
156 ms |
23884 KB |
Output is correct |
43 |
Correct |
135 ms |
22012 KB |
Output is correct |
44 |
Correct |
152 ms |
26464 KB |
Output is correct |
45 |
Correct |
165 ms |
26312 KB |
Output is correct |
46 |
Correct |
92 ms |
18244 KB |
Output is correct |
47 |
Correct |
143 ms |
23264 KB |
Output is correct |
48 |
Correct |
24 ms |
10804 KB |
Output is correct |
49 |
Correct |
252 ms |
27776 KB |
Output is correct |
50 |
Correct |
237 ms |
27196 KB |
Output is correct |
51 |
Correct |
313 ms |
26888 KB |
Output is correct |
52 |
Correct |
230 ms |
26212 KB |
Output is correct |
53 |
Correct |
207 ms |
24632 KB |
Output is correct |
54 |
Correct |
164 ms |
21180 KB |
Output is correct |
55 |
Correct |
263 ms |
27948 KB |
Output is correct |
56 |
Correct |
251 ms |
28140 KB |
Output is correct |
57 |
Correct |
165 ms |
19840 KB |
Output is correct |
58 |
Correct |
213 ms |
24904 KB |
Output is correct |
59 |
Correct |
80 ms |
14944 KB |
Output is correct |
60 |
Correct |
237 ms |
27640 KB |
Output is correct |
61 |
Correct |
273 ms |
27392 KB |
Output is correct |
62 |
Correct |
248 ms |
28444 KB |
Output is correct |
63 |
Correct |
149 ms |
19476 KB |
Output is correct |
64 |
Correct |
8 ms |
8516 KB |
Output is correct |
65 |
Correct |
8 ms |
8604 KB |
Output is correct |
66 |
Correct |
8 ms |
8532 KB |
Output is correct |
67 |
Correct |
8 ms |
8600 KB |
Output is correct |
68 |
Correct |
8 ms |
8532 KB |
Output is correct |
69 |
Correct |
8 ms |
8604 KB |
Output is correct |
70 |
Correct |
8 ms |
8644 KB |
Output is correct |
71 |
Correct |
9 ms |
8660 KB |
Output is correct |
72 |
Correct |
8 ms |
8532 KB |
Output is correct |
73 |
Correct |
8 ms |
8660 KB |
Output is correct |
74 |
Correct |
107 ms |
19120 KB |
Output is correct |
75 |
Correct |
165 ms |
25832 KB |
Output is correct |
76 |
Correct |
147 ms |
21780 KB |
Output is correct |
77 |
Correct |
114 ms |
18924 KB |
Output is correct |
78 |
Correct |
66 ms |
16140 KB |
Output is correct |
79 |
Correct |
65 ms |
13836 KB |
Output is correct |
80 |
Correct |
89 ms |
17604 KB |
Output is correct |
81 |
Correct |
179 ms |
26956 KB |
Output is correct |
82 |
Correct |
155 ms |
22780 KB |
Output is correct |
83 |
Correct |
211 ms |
29876 KB |
Output is correct |
84 |
Correct |
84 ms |
18244 KB |
Output is correct |
85 |
Correct |
141 ms |
21388 KB |
Output is correct |
86 |
Correct |
53 ms |
13244 KB |
Output is correct |
87 |
Correct |
251 ms |
26588 KB |
Output is correct |
88 |
Correct |
239 ms |
26768 KB |
Output is correct |
89 |
Correct |
188 ms |
19948 KB |
Output is correct |
90 |
Correct |
125 ms |
17900 KB |
Output is correct |
91 |
Correct |
128 ms |
17448 KB |
Output is correct |
92 |
Correct |
150 ms |
18888 KB |
Output is correct |
93 |
Correct |
250 ms |
27256 KB |
Output is correct |
94 |
Correct |
260 ms |
24768 KB |
Output is correct |
95 |
Correct |
287 ms |
31660 KB |
Output is correct |
96 |
Correct |
146 ms |
19788 KB |
Output is correct |
97 |
Correct |
252 ms |
21712 KB |
Output is correct |