#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
vector<tuple<int,int,int>> edg;
int minyes[100100],abp[100100];
map<int,int> unpersist[100100];
vector<int>v[100100];
vector<pair<int,int>> roots;
int derot,N_;
void upd(int t,int p,int v){
unpersist[p][t]=v;
}
void do_a_merge(int &x,int &y,int t){
if(v[x].size()<v[y].size())
swap(x,y);
for(auto k:v[y])
upd(t,k,x),abp[k]=x,v[x].push_back(k);
v[y].clear();
}
int par[100100],deg[100100];
bitset<100100>yes;
void init(int N,int M,vector<int>U,vector<int>V,vector<int>W) {
for(int i=1;i<=N;i++)
unpersist[i][-1]=i,abp[i]=i;
N_=N;
for(int i=1;i<=N;i++)
v[i].push_back(i);
for(int i=0;i<M;i++)
edg.push_back({W[i],++U[i],++V[i]});
for(auto&i:minyes)i=1e9+1;
sort(edg.begin(),edg.end());
int prevW=get<0>(edg[0]);
for(auto[w,u,v]:edg){
deg[u]++,deg[v]++;
if(deg[u]>2&&!yes[abp[u]])
yes[abp[u]]=1,minyes[abp[u]]=w;
if(deg[v]>2&&!yes[abp[v]])
yes[abp[v]]=1,minyes[abp[v]]=w;
u=abp[u],v=abp[v];
if(u-v) {
do_a_merge(u,v,w);
if(!yes[u]&&yes[v])
yes[u]=1,minyes[u]=w;
} else if(!yes[v])
yes[v]=1,minyes[v]=w;
prevW=w;
}
}
int ok(int t,int x,int y){
x=(--unpersist[x].upper_bound(t))->second;
y=(--unpersist[y].upper_bound(t))->second;
return x==y&&minyes[x]<=t;
}
int getMinimumFuelCapacity(int X,int Y) {
++X,++Y;
int l=1,r=1e9,res=-1;
while(l<=r){
int mid=l+r>>1;
if(ok(mid,X,Y)){
r=mid-1,res=mid;
} else {
l=mid+1;
}
}
return res;
}
Compilation message
swap.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
swap.cpp:33:9: warning: variable 'prevW' set but not used [-Wunused-but-set-variable]
33 | int prevW=get<0>(edg[0]);
| ^~~~~
swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:59:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
59 | int mid=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7772 KB |
Output is correct |
2 |
Correct |
3 ms |
7840 KB |
Output is correct |
3 |
Correct |
4 ms |
7760 KB |
Output is correct |
4 |
Correct |
4 ms |
7816 KB |
Output is correct |
5 |
Correct |
5 ms |
8028 KB |
Output is correct |
6 |
Correct |
5 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8028 KB |
Output is correct |
8 |
Correct |
4 ms |
8028 KB |
Output is correct |
9 |
Correct |
127 ms |
42944 KB |
Output is correct |
10 |
Correct |
209 ms |
50132 KB |
Output is correct |
11 |
Correct |
190 ms |
49340 KB |
Output is correct |
12 |
Correct |
203 ms |
52164 KB |
Output is correct |
13 |
Correct |
77 ms |
29600 KB |
Output is correct |
14 |
Correct |
154 ms |
42732 KB |
Output is correct |
15 |
Correct |
470 ms |
55368 KB |
Output is correct |
16 |
Correct |
521 ms |
53876 KB |
Output is correct |
17 |
Correct |
538 ms |
56884 KB |
Output is correct |
18 |
Correct |
209 ms |
33624 KB |
Output is correct |
19 |
Correct |
123 ms |
19076 KB |
Output is correct |
20 |
Correct |
458 ms |
56552 KB |
Output is correct |
21 |
Correct |
510 ms |
55116 KB |
Output is correct |
22 |
Correct |
522 ms |
58204 KB |
Output is correct |
23 |
Correct |
201 ms |
35032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7772 KB |
Output is correct |
2 |
Correct |
3 ms |
7840 KB |
Output is correct |
3 |
Correct |
194 ms |
30896 KB |
Output is correct |
4 |
Correct |
239 ms |
31556 KB |
Output is correct |
5 |
Correct |
212 ms |
31580 KB |
Output is correct |
6 |
Correct |
201 ms |
31420 KB |
Output is correct |
7 |
Correct |
192 ms |
31556 KB |
Output is correct |
8 |
Correct |
189 ms |
30844 KB |
Output is correct |
9 |
Correct |
189 ms |
31320 KB |
Output is correct |
10 |
Correct |
199 ms |
30708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7772 KB |
Output is correct |
2 |
Correct |
3 ms |
7840 KB |
Output is correct |
3 |
Correct |
4 ms |
7760 KB |
Output is correct |
4 |
Correct |
4 ms |
7816 KB |
Output is correct |
5 |
Correct |
5 ms |
8028 KB |
Output is correct |
6 |
Correct |
5 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8028 KB |
Output is correct |
8 |
Correct |
4 ms |
8028 KB |
Output is correct |
9 |
Correct |
3 ms |
7772 KB |
Output is correct |
10 |
Correct |
4 ms |
8028 KB |
Output is correct |
11 |
Correct |
4 ms |
8028 KB |
Output is correct |
12 |
Correct |
4 ms |
8028 KB |
Output is correct |
13 |
Correct |
3 ms |
8024 KB |
Output is correct |
14 |
Correct |
3 ms |
8028 KB |
Output is correct |
15 |
Correct |
4 ms |
8028 KB |
Output is correct |
16 |
Correct |
3 ms |
8024 KB |
Output is correct |
17 |
Correct |
5 ms |
8028 KB |
Output is correct |
18 |
Correct |
4 ms |
8028 KB |
Output is correct |
19 |
Correct |
4 ms |
8028 KB |
Output is correct |
20 |
Correct |
4 ms |
8028 KB |
Output is correct |
21 |
Correct |
4 ms |
8028 KB |
Output is correct |
22 |
Correct |
4 ms |
8028 KB |
Output is correct |
23 |
Correct |
4 ms |
8028 KB |
Output is correct |
24 |
Correct |
4 ms |
8024 KB |
Output is correct |
25 |
Correct |
4 ms |
8028 KB |
Output is correct |
26 |
Correct |
6 ms |
8284 KB |
Output is correct |
27 |
Correct |
4 ms |
8028 KB |
Output is correct |
28 |
Correct |
4 ms |
8028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7772 KB |
Output is correct |
2 |
Correct |
3 ms |
7772 KB |
Output is correct |
3 |
Correct |
3 ms |
7840 KB |
Output is correct |
4 |
Correct |
4 ms |
7760 KB |
Output is correct |
5 |
Correct |
4 ms |
7816 KB |
Output is correct |
6 |
Correct |
5 ms |
8028 KB |
Output is correct |
7 |
Correct |
5 ms |
8028 KB |
Output is correct |
8 |
Correct |
4 ms |
8028 KB |
Output is correct |
9 |
Correct |
4 ms |
8028 KB |
Output is correct |
10 |
Correct |
127 ms |
42944 KB |
Output is correct |
11 |
Correct |
209 ms |
50132 KB |
Output is correct |
12 |
Correct |
190 ms |
49340 KB |
Output is correct |
13 |
Correct |
203 ms |
52164 KB |
Output is correct |
14 |
Correct |
77 ms |
29600 KB |
Output is correct |
15 |
Correct |
4 ms |
8028 KB |
Output is correct |
16 |
Correct |
4 ms |
8028 KB |
Output is correct |
17 |
Correct |
4 ms |
8028 KB |
Output is correct |
18 |
Correct |
3 ms |
8024 KB |
Output is correct |
19 |
Correct |
3 ms |
8028 KB |
Output is correct |
20 |
Correct |
4 ms |
8028 KB |
Output is correct |
21 |
Correct |
3 ms |
8024 KB |
Output is correct |
22 |
Correct |
5 ms |
8028 KB |
Output is correct |
23 |
Correct |
4 ms |
8028 KB |
Output is correct |
24 |
Correct |
4 ms |
8028 KB |
Output is correct |
25 |
Correct |
4 ms |
8028 KB |
Output is correct |
26 |
Correct |
4 ms |
8028 KB |
Output is correct |
27 |
Correct |
4 ms |
8028 KB |
Output is correct |
28 |
Correct |
4 ms |
8028 KB |
Output is correct |
29 |
Correct |
4 ms |
8024 KB |
Output is correct |
30 |
Correct |
4 ms |
8028 KB |
Output is correct |
31 |
Correct |
6 ms |
8284 KB |
Output is correct |
32 |
Correct |
4 ms |
8028 KB |
Output is correct |
33 |
Correct |
4 ms |
8028 KB |
Output is correct |
34 |
Correct |
14 ms |
12316 KB |
Output is correct |
35 |
Correct |
181 ms |
51528 KB |
Output is correct |
36 |
Correct |
227 ms |
50388 KB |
Output is correct |
37 |
Correct |
218 ms |
48720 KB |
Output is correct |
38 |
Correct |
198 ms |
46028 KB |
Output is correct |
39 |
Correct |
152 ms |
45000 KB |
Output is correct |
40 |
Correct |
128 ms |
40604 KB |
Output is correct |
41 |
Correct |
204 ms |
53192 KB |
Output is correct |
42 |
Correct |
201 ms |
52936 KB |
Output is correct |
43 |
Correct |
67 ms |
28496 KB |
Output is correct |
44 |
Correct |
136 ms |
43924 KB |
Output is correct |
45 |
Correct |
91 ms |
31420 KB |
Output is correct |
46 |
Correct |
160 ms |
50508 KB |
Output is correct |
47 |
Correct |
142 ms |
39828 KB |
Output is correct |
48 |
Correct |
91 ms |
32456 KB |
Output is correct |
49 |
Correct |
46 ms |
17092 KB |
Output is correct |
50 |
Correct |
37 ms |
15684 KB |
Output is correct |
51 |
Correct |
79 ms |
27300 KB |
Output is correct |
52 |
Correct |
213 ms |
51176 KB |
Output is correct |
53 |
Correct |
138 ms |
40096 KB |
Output is correct |
54 |
Correct |
231 ms |
58212 KB |
Output is correct |
55 |
Correct |
90 ms |
28712 KB |
Output is correct |
56 |
Correct |
145 ms |
37316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7772 KB |
Output is correct |
2 |
Correct |
3 ms |
7840 KB |
Output is correct |
3 |
Correct |
4 ms |
7760 KB |
Output is correct |
4 |
Correct |
4 ms |
7816 KB |
Output is correct |
5 |
Correct |
5 ms |
8028 KB |
Output is correct |
6 |
Correct |
5 ms |
8028 KB |
Output is correct |
7 |
Correct |
4 ms |
8028 KB |
Output is correct |
8 |
Correct |
4 ms |
8028 KB |
Output is correct |
9 |
Correct |
127 ms |
42944 KB |
Output is correct |
10 |
Correct |
209 ms |
50132 KB |
Output is correct |
11 |
Correct |
190 ms |
49340 KB |
Output is correct |
12 |
Correct |
203 ms |
52164 KB |
Output is correct |
13 |
Correct |
77 ms |
29600 KB |
Output is correct |
14 |
Correct |
154 ms |
42732 KB |
Output is correct |
15 |
Correct |
470 ms |
55368 KB |
Output is correct |
16 |
Correct |
521 ms |
53876 KB |
Output is correct |
17 |
Correct |
538 ms |
56884 KB |
Output is correct |
18 |
Correct |
209 ms |
33624 KB |
Output is correct |
19 |
Correct |
194 ms |
30896 KB |
Output is correct |
20 |
Correct |
239 ms |
31556 KB |
Output is correct |
21 |
Correct |
212 ms |
31580 KB |
Output is correct |
22 |
Correct |
201 ms |
31420 KB |
Output is correct |
23 |
Correct |
192 ms |
31556 KB |
Output is correct |
24 |
Correct |
189 ms |
30844 KB |
Output is correct |
25 |
Correct |
189 ms |
31320 KB |
Output is correct |
26 |
Correct |
199 ms |
30708 KB |
Output is correct |
27 |
Correct |
4 ms |
8028 KB |
Output is correct |
28 |
Correct |
4 ms |
8028 KB |
Output is correct |
29 |
Correct |
4 ms |
8028 KB |
Output is correct |
30 |
Correct |
3 ms |
8024 KB |
Output is correct |
31 |
Correct |
3 ms |
8028 KB |
Output is correct |
32 |
Correct |
4 ms |
8028 KB |
Output is correct |
33 |
Correct |
3 ms |
8024 KB |
Output is correct |
34 |
Correct |
5 ms |
8028 KB |
Output is correct |
35 |
Correct |
4 ms |
8028 KB |
Output is correct |
36 |
Correct |
14 ms |
12316 KB |
Output is correct |
37 |
Correct |
181 ms |
51528 KB |
Output is correct |
38 |
Correct |
227 ms |
50388 KB |
Output is correct |
39 |
Correct |
218 ms |
48720 KB |
Output is correct |
40 |
Correct |
198 ms |
46028 KB |
Output is correct |
41 |
Correct |
152 ms |
45000 KB |
Output is correct |
42 |
Correct |
128 ms |
40604 KB |
Output is correct |
43 |
Correct |
204 ms |
53192 KB |
Output is correct |
44 |
Correct |
201 ms |
52936 KB |
Output is correct |
45 |
Correct |
67 ms |
28496 KB |
Output is correct |
46 |
Correct |
136 ms |
43924 KB |
Output is correct |
47 |
Correct |
31 ms |
12516 KB |
Output is correct |
48 |
Correct |
425 ms |
56620 KB |
Output is correct |
49 |
Correct |
415 ms |
54860 KB |
Output is correct |
50 |
Correct |
410 ms |
54356 KB |
Output is correct |
51 |
Correct |
437 ms |
52276 KB |
Output is correct |
52 |
Correct |
331 ms |
47924 KB |
Output is correct |
53 |
Correct |
319 ms |
37060 KB |
Output is correct |
54 |
Correct |
393 ms |
57148 KB |
Output is correct |
55 |
Correct |
466 ms |
58436 KB |
Output is correct |
56 |
Correct |
210 ms |
34228 KB |
Output is correct |
57 |
Correct |
396 ms |
48448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7772 KB |
Output is correct |
2 |
Correct |
3 ms |
7772 KB |
Output is correct |
3 |
Correct |
3 ms |
7840 KB |
Output is correct |
4 |
Correct |
4 ms |
7760 KB |
Output is correct |
5 |
Correct |
4 ms |
7816 KB |
Output is correct |
6 |
Correct |
5 ms |
8028 KB |
Output is correct |
7 |
Correct |
5 ms |
8028 KB |
Output is correct |
8 |
Correct |
4 ms |
8028 KB |
Output is correct |
9 |
Correct |
4 ms |
8028 KB |
Output is correct |
10 |
Correct |
127 ms |
42944 KB |
Output is correct |
11 |
Correct |
209 ms |
50132 KB |
Output is correct |
12 |
Correct |
190 ms |
49340 KB |
Output is correct |
13 |
Correct |
203 ms |
52164 KB |
Output is correct |
14 |
Correct |
77 ms |
29600 KB |
Output is correct |
15 |
Correct |
154 ms |
42732 KB |
Output is correct |
16 |
Correct |
470 ms |
55368 KB |
Output is correct |
17 |
Correct |
521 ms |
53876 KB |
Output is correct |
18 |
Correct |
538 ms |
56884 KB |
Output is correct |
19 |
Correct |
209 ms |
33624 KB |
Output is correct |
20 |
Correct |
194 ms |
30896 KB |
Output is correct |
21 |
Correct |
239 ms |
31556 KB |
Output is correct |
22 |
Correct |
212 ms |
31580 KB |
Output is correct |
23 |
Correct |
201 ms |
31420 KB |
Output is correct |
24 |
Correct |
192 ms |
31556 KB |
Output is correct |
25 |
Correct |
189 ms |
30844 KB |
Output is correct |
26 |
Correct |
189 ms |
31320 KB |
Output is correct |
27 |
Correct |
199 ms |
30708 KB |
Output is correct |
28 |
Correct |
4 ms |
8028 KB |
Output is correct |
29 |
Correct |
4 ms |
8028 KB |
Output is correct |
30 |
Correct |
4 ms |
8028 KB |
Output is correct |
31 |
Correct |
3 ms |
8024 KB |
Output is correct |
32 |
Correct |
3 ms |
8028 KB |
Output is correct |
33 |
Correct |
4 ms |
8028 KB |
Output is correct |
34 |
Correct |
3 ms |
8024 KB |
Output is correct |
35 |
Correct |
5 ms |
8028 KB |
Output is correct |
36 |
Correct |
4 ms |
8028 KB |
Output is correct |
37 |
Correct |
14 ms |
12316 KB |
Output is correct |
38 |
Correct |
181 ms |
51528 KB |
Output is correct |
39 |
Correct |
227 ms |
50388 KB |
Output is correct |
40 |
Correct |
218 ms |
48720 KB |
Output is correct |
41 |
Correct |
198 ms |
46028 KB |
Output is correct |
42 |
Correct |
152 ms |
45000 KB |
Output is correct |
43 |
Correct |
128 ms |
40604 KB |
Output is correct |
44 |
Correct |
204 ms |
53192 KB |
Output is correct |
45 |
Correct |
201 ms |
52936 KB |
Output is correct |
46 |
Correct |
67 ms |
28496 KB |
Output is correct |
47 |
Correct |
136 ms |
43924 KB |
Output is correct |
48 |
Correct |
31 ms |
12516 KB |
Output is correct |
49 |
Correct |
425 ms |
56620 KB |
Output is correct |
50 |
Correct |
415 ms |
54860 KB |
Output is correct |
51 |
Correct |
410 ms |
54356 KB |
Output is correct |
52 |
Correct |
437 ms |
52276 KB |
Output is correct |
53 |
Correct |
331 ms |
47924 KB |
Output is correct |
54 |
Correct |
319 ms |
37060 KB |
Output is correct |
55 |
Correct |
393 ms |
57148 KB |
Output is correct |
56 |
Correct |
466 ms |
58436 KB |
Output is correct |
57 |
Correct |
210 ms |
34228 KB |
Output is correct |
58 |
Correct |
396 ms |
48448 KB |
Output is correct |
59 |
Correct |
123 ms |
19076 KB |
Output is correct |
60 |
Correct |
458 ms |
56552 KB |
Output is correct |
61 |
Correct |
510 ms |
55116 KB |
Output is correct |
62 |
Correct |
522 ms |
58204 KB |
Output is correct |
63 |
Correct |
201 ms |
35032 KB |
Output is correct |
64 |
Correct |
4 ms |
8028 KB |
Output is correct |
65 |
Correct |
4 ms |
8028 KB |
Output is correct |
66 |
Correct |
4 ms |
8028 KB |
Output is correct |
67 |
Correct |
4 ms |
8028 KB |
Output is correct |
68 |
Correct |
4 ms |
8028 KB |
Output is correct |
69 |
Correct |
4 ms |
8024 KB |
Output is correct |
70 |
Correct |
4 ms |
8028 KB |
Output is correct |
71 |
Correct |
6 ms |
8284 KB |
Output is correct |
72 |
Correct |
4 ms |
8028 KB |
Output is correct |
73 |
Correct |
4 ms |
8028 KB |
Output is correct |
74 |
Correct |
91 ms |
31420 KB |
Output is correct |
75 |
Correct |
160 ms |
50508 KB |
Output is correct |
76 |
Correct |
142 ms |
39828 KB |
Output is correct |
77 |
Correct |
91 ms |
32456 KB |
Output is correct |
78 |
Correct |
46 ms |
17092 KB |
Output is correct |
79 |
Correct |
37 ms |
15684 KB |
Output is correct |
80 |
Correct |
79 ms |
27300 KB |
Output is correct |
81 |
Correct |
213 ms |
51176 KB |
Output is correct |
82 |
Correct |
138 ms |
40096 KB |
Output is correct |
83 |
Correct |
231 ms |
58212 KB |
Output is correct |
84 |
Correct |
90 ms |
28712 KB |
Output is correct |
85 |
Correct |
145 ms |
37316 KB |
Output is correct |
86 |
Correct |
61 ms |
17716 KB |
Output is correct |
87 |
Correct |
401 ms |
52784 KB |
Output is correct |
88 |
Correct |
350 ms |
53556 KB |
Output is correct |
89 |
Correct |
211 ms |
36164 KB |
Output is correct |
90 |
Correct |
196 ms |
20956 KB |
Output is correct |
91 |
Correct |
160 ms |
22504 KB |
Output is correct |
92 |
Correct |
229 ms |
32300 KB |
Output is correct |
93 |
Correct |
364 ms |
53660 KB |
Output is correct |
94 |
Correct |
293 ms |
45752 KB |
Output is correct |
95 |
Correct |
450 ms |
63176 KB |
Output is correct |
96 |
Correct |
195 ms |
34140 KB |
Output is correct |
97 |
Correct |
267 ms |
40840 KB |
Output is correct |