#include "swap.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define ep insert
#define pb push_back
using namespace std;
struct edge{
int x,y,w;
};
const int NN=7e5+5;
int n,m,p[NN],val[NN],f[NN],c,lg[NN],deg[NN],dis[NN],par[25][NN];
pair<int,int> st[25][NN];
bool spec[NN];
edge e[NN];
vector<int> adj[NN];
bool cmp(edge x,edge y){
return x.w<y.w;
}
int getpar(int x){
if (x==p[x]) return x;
return p[x]=getpar(p[x]);
}
void link(int x,int y){
x=getpar(x);y=getpar(y);
if (x==y) return;
p[x]=y;
adj[y].pb(x);
return;
}
void dfs(int x){
st[0][++c]={dis[x],x};
f[x]=c;
for (auto u:adj[x]){
par[0][u]=x;
dis[u]=dis[x]+1;
dfs(u);
st[0][++c]={dis[x],x};
}return;
}
void build(){
for (int i=1;i<25;i++) for (int j=1;j+(1<<i)<=c+1;j++) st[i][j]=min(st[i-1][j],st[i-1][j+(1<<(i-1))]);
for (int i=1;i<25;i++) for (int j=1;j<=n+m;j++) par[i][j]=par[i-1][par[i-1][j]];
return;
}
int query(int l,int r){
if (l>r) swap(l,r);
int i=lg[r-l+1];
//cout<<l<<' '<<r<<' '<<i<<endl;
return min(st[i][l],st[i][r-(1<<i)+1]).S;
}
void init(int N, int M,
vector<int> U, vector<int> V, vector<int> W) {
for (int i=2;i<NN;i++) lg[i]=lg[i/2]+1;
n=N,m=M;dis[0]=-1;
for (int i=0;i<m;i++) e[i+1]={U[i]+1,V[i]+1,W[i]};
sort(e+1,e+1+m,cmp);
for (int i=1;i<=n+m;i++) p[i]=i;
for (int i=1;i<=m;i++){
val[i+n]=e[i].w;
deg[e[i].x]++;
deg[e[i].y]++;
if (deg[e[i].x]>=3 || deg[e[i].y]>=3) spec[i+n]=1;
int x=getpar(e[i].x),y=getpar(e[i].y);
if (x==y){
spec[i+n]=1;
link(x,i+n);
}
else{
link(x,i+n);
link(y,i+n);
}
for (auto u:adj[i+n]) spec[i+n]|=spec[u];
}
dfs(n+m);
build();
/*for (int i=0;i<5;i++){
for (int j=1;j+(1<<i)<=c+1;j++) cout<<st[i][j].S<<' ';
cout<<endl;
}*/
return;
}
int getMinimumFuelCapacity(int x, int y) {
if (!spec[n+m]) return -1;
x++;y++;
int lca=query(f[x],f[y]);
//cout<<lca<<endl;
if (spec[lca]) return val[lca];
for (int i=24;i>=0;i--){
if (par[i][lca]==0) continue;
if (spec[par[i][lca]]) continue;
lca=par[i][lca];
}
return val[par[0][lca]];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
86580 KB |
Output is correct |
2 |
Correct |
13 ms |
88668 KB |
Output is correct |
3 |
Correct |
12 ms |
88584 KB |
Output is correct |
4 |
Correct |
18 ms |
103004 KB |
Output is correct |
5 |
Correct |
15 ms |
105052 KB |
Output is correct |
6 |
Correct |
15 ms |
105052 KB |
Output is correct |
7 |
Correct |
15 ms |
105052 KB |
Output is correct |
8 |
Correct |
15 ms |
105092 KB |
Output is correct |
9 |
Correct |
87 ms |
150208 KB |
Output is correct |
10 |
Correct |
92 ms |
158032 KB |
Output is correct |
11 |
Correct |
84 ms |
157780 KB |
Output is correct |
12 |
Correct |
92 ms |
158996 KB |
Output is correct |
13 |
Correct |
83 ms |
162132 KB |
Output is correct |
14 |
Correct |
76 ms |
150356 KB |
Output is correct |
15 |
Correct |
131 ms |
160172 KB |
Output is correct |
16 |
Correct |
125 ms |
160772 KB |
Output is correct |
17 |
Correct |
161 ms |
160696 KB |
Output is correct |
18 |
Correct |
123 ms |
164024 KB |
Output is correct |
19 |
Correct |
74 ms |
131920 KB |
Output is correct |
20 |
Correct |
158 ms |
163028 KB |
Output is correct |
21 |
Correct |
159 ms |
161664 KB |
Output is correct |
22 |
Correct |
167 ms |
162280 KB |
Output is correct |
23 |
Correct |
222 ms |
167608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
86580 KB |
Output is correct |
2 |
Correct |
13 ms |
88668 KB |
Output is correct |
3 |
Correct |
131 ms |
164852 KB |
Output is correct |
4 |
Correct |
129 ms |
165560 KB |
Output is correct |
5 |
Correct |
133 ms |
164700 KB |
Output is correct |
6 |
Correct |
128 ms |
168380 KB |
Output is correct |
7 |
Correct |
134 ms |
167048 KB |
Output is correct |
8 |
Correct |
133 ms |
165728 KB |
Output is correct |
9 |
Correct |
131 ms |
166616 KB |
Output is correct |
10 |
Correct |
130 ms |
166668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
86580 KB |
Output is correct |
2 |
Correct |
13 ms |
88668 KB |
Output is correct |
3 |
Correct |
12 ms |
88584 KB |
Output is correct |
4 |
Correct |
18 ms |
103004 KB |
Output is correct |
5 |
Correct |
15 ms |
105052 KB |
Output is correct |
6 |
Correct |
15 ms |
105052 KB |
Output is correct |
7 |
Correct |
15 ms |
105052 KB |
Output is correct |
8 |
Correct |
15 ms |
105092 KB |
Output is correct |
9 |
Correct |
12 ms |
90716 KB |
Output is correct |
10 |
Correct |
15 ms |
105160 KB |
Output is correct |
11 |
Correct |
14 ms |
105052 KB |
Output is correct |
12 |
Correct |
14 ms |
105144 KB |
Output is correct |
13 |
Correct |
15 ms |
105048 KB |
Output is correct |
14 |
Correct |
15 ms |
105164 KB |
Output is correct |
15 |
Correct |
15 ms |
105052 KB |
Output is correct |
16 |
Correct |
15 ms |
105052 KB |
Output is correct |
17 |
Correct |
15 ms |
105068 KB |
Output is correct |
18 |
Correct |
17 ms |
105324 KB |
Output is correct |
19 |
Correct |
16 ms |
105300 KB |
Output is correct |
20 |
Correct |
14 ms |
105048 KB |
Output is correct |
21 |
Correct |
14 ms |
105052 KB |
Output is correct |
22 |
Correct |
15 ms |
105304 KB |
Output is correct |
23 |
Correct |
15 ms |
105052 KB |
Output is correct |
24 |
Correct |
16 ms |
107356 KB |
Output is correct |
25 |
Correct |
15 ms |
107352 KB |
Output is correct |
26 |
Correct |
17 ms |
107352 KB |
Output is correct |
27 |
Correct |
15 ms |
105048 KB |
Output is correct |
28 |
Correct |
16 ms |
107624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
90716 KB |
Output is correct |
2 |
Correct |
27 ms |
86580 KB |
Output is correct |
3 |
Correct |
13 ms |
88668 KB |
Output is correct |
4 |
Correct |
12 ms |
88584 KB |
Output is correct |
5 |
Correct |
18 ms |
103004 KB |
Output is correct |
6 |
Correct |
15 ms |
105052 KB |
Output is correct |
7 |
Correct |
15 ms |
105052 KB |
Output is correct |
8 |
Correct |
15 ms |
105052 KB |
Output is correct |
9 |
Correct |
15 ms |
105092 KB |
Output is correct |
10 |
Correct |
87 ms |
150208 KB |
Output is correct |
11 |
Correct |
92 ms |
158032 KB |
Output is correct |
12 |
Correct |
84 ms |
157780 KB |
Output is correct |
13 |
Correct |
92 ms |
158996 KB |
Output is correct |
14 |
Correct |
83 ms |
162132 KB |
Output is correct |
15 |
Correct |
15 ms |
105160 KB |
Output is correct |
16 |
Correct |
14 ms |
105052 KB |
Output is correct |
17 |
Correct |
14 ms |
105144 KB |
Output is correct |
18 |
Correct |
15 ms |
105048 KB |
Output is correct |
19 |
Correct |
15 ms |
105164 KB |
Output is correct |
20 |
Correct |
15 ms |
105052 KB |
Output is correct |
21 |
Correct |
15 ms |
105052 KB |
Output is correct |
22 |
Correct |
15 ms |
105068 KB |
Output is correct |
23 |
Correct |
17 ms |
105324 KB |
Output is correct |
24 |
Correct |
16 ms |
105300 KB |
Output is correct |
25 |
Correct |
14 ms |
105048 KB |
Output is correct |
26 |
Correct |
14 ms |
105052 KB |
Output is correct |
27 |
Correct |
15 ms |
105304 KB |
Output is correct |
28 |
Correct |
15 ms |
105052 KB |
Output is correct |
29 |
Correct |
16 ms |
107356 KB |
Output is correct |
30 |
Correct |
15 ms |
107352 KB |
Output is correct |
31 |
Correct |
17 ms |
107352 KB |
Output is correct |
32 |
Correct |
15 ms |
105048 KB |
Output is correct |
33 |
Correct |
16 ms |
107624 KB |
Output is correct |
34 |
Correct |
25 ms |
126556 KB |
Output is correct |
35 |
Correct |
99 ms |
159468 KB |
Output is correct |
36 |
Correct |
90 ms |
158488 KB |
Output is correct |
37 |
Correct |
92 ms |
159556 KB |
Output is correct |
38 |
Correct |
96 ms |
157716 KB |
Output is correct |
39 |
Correct |
90 ms |
159076 KB |
Output is correct |
40 |
Correct |
85 ms |
153936 KB |
Output is correct |
41 |
Correct |
95 ms |
158792 KB |
Output is correct |
42 |
Correct |
90 ms |
158548 KB |
Output is correct |
43 |
Correct |
81 ms |
163808 KB |
Output is correct |
44 |
Correct |
93 ms |
158804 KB |
Output is correct |
45 |
Correct |
142 ms |
171416 KB |
Output is correct |
46 |
Correct |
99 ms |
162128 KB |
Output is correct |
47 |
Correct |
89 ms |
160844 KB |
Output is correct |
48 |
Correct |
96 ms |
164948 KB |
Output is correct |
49 |
Correct |
97 ms |
166976 KB |
Output is correct |
50 |
Correct |
84 ms |
157268 KB |
Output is correct |
51 |
Correct |
105 ms |
168272 KB |
Output is correct |
52 |
Correct |
129 ms |
178260 KB |
Output is correct |
53 |
Correct |
149 ms |
180268 KB |
Output is correct |
54 |
Correct |
161 ms |
187328 KB |
Output is correct |
55 |
Correct |
84 ms |
162388 KB |
Output is correct |
56 |
Correct |
143 ms |
181584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
86580 KB |
Output is correct |
2 |
Correct |
13 ms |
88668 KB |
Output is correct |
3 |
Correct |
12 ms |
88584 KB |
Output is correct |
4 |
Correct |
18 ms |
103004 KB |
Output is correct |
5 |
Correct |
15 ms |
105052 KB |
Output is correct |
6 |
Correct |
15 ms |
105052 KB |
Output is correct |
7 |
Correct |
15 ms |
105052 KB |
Output is correct |
8 |
Correct |
15 ms |
105092 KB |
Output is correct |
9 |
Correct |
87 ms |
150208 KB |
Output is correct |
10 |
Correct |
92 ms |
158032 KB |
Output is correct |
11 |
Correct |
84 ms |
157780 KB |
Output is correct |
12 |
Correct |
92 ms |
158996 KB |
Output is correct |
13 |
Correct |
83 ms |
162132 KB |
Output is correct |
14 |
Correct |
76 ms |
150356 KB |
Output is correct |
15 |
Correct |
131 ms |
160172 KB |
Output is correct |
16 |
Correct |
125 ms |
160772 KB |
Output is correct |
17 |
Correct |
161 ms |
160696 KB |
Output is correct |
18 |
Correct |
123 ms |
164024 KB |
Output is correct |
19 |
Correct |
131 ms |
164852 KB |
Output is correct |
20 |
Correct |
129 ms |
165560 KB |
Output is correct |
21 |
Correct |
133 ms |
164700 KB |
Output is correct |
22 |
Correct |
128 ms |
168380 KB |
Output is correct |
23 |
Correct |
134 ms |
167048 KB |
Output is correct |
24 |
Correct |
133 ms |
165728 KB |
Output is correct |
25 |
Correct |
131 ms |
166616 KB |
Output is correct |
26 |
Correct |
130 ms |
166668 KB |
Output is correct |
27 |
Correct |
15 ms |
105160 KB |
Output is correct |
28 |
Correct |
14 ms |
105052 KB |
Output is correct |
29 |
Correct |
14 ms |
105144 KB |
Output is correct |
30 |
Correct |
15 ms |
105048 KB |
Output is correct |
31 |
Correct |
15 ms |
105164 KB |
Output is correct |
32 |
Correct |
15 ms |
105052 KB |
Output is correct |
33 |
Correct |
15 ms |
105052 KB |
Output is correct |
34 |
Correct |
15 ms |
105068 KB |
Output is correct |
35 |
Correct |
17 ms |
105324 KB |
Output is correct |
36 |
Correct |
25 ms |
126556 KB |
Output is correct |
37 |
Correct |
99 ms |
159468 KB |
Output is correct |
38 |
Correct |
90 ms |
158488 KB |
Output is correct |
39 |
Correct |
92 ms |
159556 KB |
Output is correct |
40 |
Correct |
96 ms |
157716 KB |
Output is correct |
41 |
Correct |
90 ms |
159076 KB |
Output is correct |
42 |
Correct |
85 ms |
153936 KB |
Output is correct |
43 |
Correct |
95 ms |
158792 KB |
Output is correct |
44 |
Correct |
90 ms |
158548 KB |
Output is correct |
45 |
Correct |
81 ms |
163808 KB |
Output is correct |
46 |
Correct |
93 ms |
158804 KB |
Output is correct |
47 |
Correct |
29 ms |
125016 KB |
Output is correct |
48 |
Correct |
153 ms |
165816 KB |
Output is correct |
49 |
Correct |
144 ms |
165780 KB |
Output is correct |
50 |
Correct |
163 ms |
164624 KB |
Output is correct |
51 |
Correct |
157 ms |
164544 KB |
Output is correct |
52 |
Correct |
143 ms |
161708 KB |
Output is correct |
53 |
Correct |
117 ms |
147956 KB |
Output is correct |
54 |
Correct |
161 ms |
162740 KB |
Output is correct |
55 |
Correct |
154 ms |
162748 KB |
Output is correct |
56 |
Correct |
140 ms |
166804 KB |
Output is correct |
57 |
Correct |
154 ms |
165440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
90716 KB |
Output is correct |
2 |
Correct |
27 ms |
86580 KB |
Output is correct |
3 |
Correct |
13 ms |
88668 KB |
Output is correct |
4 |
Correct |
12 ms |
88584 KB |
Output is correct |
5 |
Correct |
18 ms |
103004 KB |
Output is correct |
6 |
Correct |
15 ms |
105052 KB |
Output is correct |
7 |
Correct |
15 ms |
105052 KB |
Output is correct |
8 |
Correct |
15 ms |
105052 KB |
Output is correct |
9 |
Correct |
15 ms |
105092 KB |
Output is correct |
10 |
Correct |
87 ms |
150208 KB |
Output is correct |
11 |
Correct |
92 ms |
158032 KB |
Output is correct |
12 |
Correct |
84 ms |
157780 KB |
Output is correct |
13 |
Correct |
92 ms |
158996 KB |
Output is correct |
14 |
Correct |
83 ms |
162132 KB |
Output is correct |
15 |
Correct |
76 ms |
150356 KB |
Output is correct |
16 |
Correct |
131 ms |
160172 KB |
Output is correct |
17 |
Correct |
125 ms |
160772 KB |
Output is correct |
18 |
Correct |
161 ms |
160696 KB |
Output is correct |
19 |
Correct |
123 ms |
164024 KB |
Output is correct |
20 |
Correct |
131 ms |
164852 KB |
Output is correct |
21 |
Correct |
129 ms |
165560 KB |
Output is correct |
22 |
Correct |
133 ms |
164700 KB |
Output is correct |
23 |
Correct |
128 ms |
168380 KB |
Output is correct |
24 |
Correct |
134 ms |
167048 KB |
Output is correct |
25 |
Correct |
133 ms |
165728 KB |
Output is correct |
26 |
Correct |
131 ms |
166616 KB |
Output is correct |
27 |
Correct |
130 ms |
166668 KB |
Output is correct |
28 |
Correct |
15 ms |
105160 KB |
Output is correct |
29 |
Correct |
14 ms |
105052 KB |
Output is correct |
30 |
Correct |
14 ms |
105144 KB |
Output is correct |
31 |
Correct |
15 ms |
105048 KB |
Output is correct |
32 |
Correct |
15 ms |
105164 KB |
Output is correct |
33 |
Correct |
15 ms |
105052 KB |
Output is correct |
34 |
Correct |
15 ms |
105052 KB |
Output is correct |
35 |
Correct |
15 ms |
105068 KB |
Output is correct |
36 |
Correct |
17 ms |
105324 KB |
Output is correct |
37 |
Correct |
25 ms |
126556 KB |
Output is correct |
38 |
Correct |
99 ms |
159468 KB |
Output is correct |
39 |
Correct |
90 ms |
158488 KB |
Output is correct |
40 |
Correct |
92 ms |
159556 KB |
Output is correct |
41 |
Correct |
96 ms |
157716 KB |
Output is correct |
42 |
Correct |
90 ms |
159076 KB |
Output is correct |
43 |
Correct |
85 ms |
153936 KB |
Output is correct |
44 |
Correct |
95 ms |
158792 KB |
Output is correct |
45 |
Correct |
90 ms |
158548 KB |
Output is correct |
46 |
Correct |
81 ms |
163808 KB |
Output is correct |
47 |
Correct |
93 ms |
158804 KB |
Output is correct |
48 |
Correct |
29 ms |
125016 KB |
Output is correct |
49 |
Correct |
153 ms |
165816 KB |
Output is correct |
50 |
Correct |
144 ms |
165780 KB |
Output is correct |
51 |
Correct |
163 ms |
164624 KB |
Output is correct |
52 |
Correct |
157 ms |
164544 KB |
Output is correct |
53 |
Correct |
143 ms |
161708 KB |
Output is correct |
54 |
Correct |
117 ms |
147956 KB |
Output is correct |
55 |
Correct |
161 ms |
162740 KB |
Output is correct |
56 |
Correct |
154 ms |
162748 KB |
Output is correct |
57 |
Correct |
140 ms |
166804 KB |
Output is correct |
58 |
Correct |
154 ms |
165440 KB |
Output is correct |
59 |
Correct |
74 ms |
131920 KB |
Output is correct |
60 |
Correct |
158 ms |
163028 KB |
Output is correct |
61 |
Correct |
159 ms |
161664 KB |
Output is correct |
62 |
Correct |
167 ms |
162280 KB |
Output is correct |
63 |
Correct |
222 ms |
167608 KB |
Output is correct |
64 |
Correct |
16 ms |
105300 KB |
Output is correct |
65 |
Correct |
14 ms |
105048 KB |
Output is correct |
66 |
Correct |
14 ms |
105052 KB |
Output is correct |
67 |
Correct |
15 ms |
105304 KB |
Output is correct |
68 |
Correct |
15 ms |
105052 KB |
Output is correct |
69 |
Correct |
16 ms |
107356 KB |
Output is correct |
70 |
Correct |
15 ms |
107352 KB |
Output is correct |
71 |
Correct |
17 ms |
107352 KB |
Output is correct |
72 |
Correct |
15 ms |
105048 KB |
Output is correct |
73 |
Correct |
16 ms |
107624 KB |
Output is correct |
74 |
Correct |
142 ms |
171416 KB |
Output is correct |
75 |
Correct |
99 ms |
162128 KB |
Output is correct |
76 |
Correct |
89 ms |
160844 KB |
Output is correct |
77 |
Correct |
96 ms |
164948 KB |
Output is correct |
78 |
Correct |
97 ms |
166976 KB |
Output is correct |
79 |
Correct |
84 ms |
157268 KB |
Output is correct |
80 |
Correct |
105 ms |
168272 KB |
Output is correct |
81 |
Correct |
129 ms |
178260 KB |
Output is correct |
82 |
Correct |
149 ms |
180268 KB |
Output is correct |
83 |
Correct |
161 ms |
187328 KB |
Output is correct |
84 |
Correct |
84 ms |
162388 KB |
Output is correct |
85 |
Correct |
143 ms |
181584 KB |
Output is correct |
86 |
Correct |
61 ms |
138244 KB |
Output is correct |
87 |
Correct |
166 ms |
164544 KB |
Output is correct |
88 |
Correct |
154 ms |
164536 KB |
Output is correct |
89 |
Correct |
184 ms |
165992 KB |
Output is correct |
90 |
Correct |
151 ms |
170744 KB |
Output is correct |
91 |
Correct |
158 ms |
166964 KB |
Output is correct |
92 |
Correct |
159 ms |
167460 KB |
Output is correct |
93 |
Correct |
192 ms |
180236 KB |
Output is correct |
94 |
Correct |
227 ms |
182580 KB |
Output is correct |
95 |
Correct |
220 ms |
191060 KB |
Output is correct |
96 |
Correct |
141 ms |
167124 KB |
Output is correct |
97 |
Correct |
172 ms |
174868 KB |
Output is correct |