#include "swap.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) x.begin(),x.end()
using ll=long long;
struct PersUF{
int size;
int time=-1;
//時間,親,flg
vector<vector<array<int,3>>> tree;
PersUF(int sz){
size=sz;
tree.resize(sz,{{-1,-1,0}});
}
int root(int pos,int tim){
while(true){
int ok=0,ng=tree[pos].size();
while(ng-ok>1){
int mid=(ok+ng)/2;
if(tree[pos][mid][0]<=tim){
ok=mid;
}
else{
ng=mid;
}
}
if(tree[pos][ok][1]<0)return pos;
pos=tree[pos][ok][1];
}
}
int isok(int pos,int tim){
while(true){
int ok=0,ng=tree[pos].size();
while(ng-ok>1){
int mid=(ok+ng)/2;
if(tree[pos][mid][0]<=tim){
ok=mid;
}
else{
ng=mid;
}
}
if(tree[pos][ok][1]<0)return tree[pos][ok][2];
pos=tree[pos][ok][1];
}
}
bool same(int s,int t,int tim){
return root(s,tim)==root(t,tim);
}
void merge(int s,int t){
time++;
s=root(s,time);
t=root(t,time);
if(s==t){
if(tree[s].back()[2])return;
tree[s].emplace_back(tree[s].back());
tree[s].back()[0]=time;
tree[s].back()[2]=1;
return;
}
if(-tree[s].back()[1]<-tree[t].back()[1])swap(s,t);
tree[s].emplace_back(tree[s].back());
tree[t].emplace_back(tree[t].back());
tree[s].back()[0]=time;
tree[t].back()[0]=time;
tree[s].back()[1]+=tree[t].back()[1];
tree[t].back()[1]=s;
tree[s].back()[2]|=tree[t].back()[2];
}
};
vector<array<int,3>> edge;
PersUF uni(0);
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
uni=PersUF(N);
edge.resize(M);
rep(i,M){
edge[i]={W[i],U[i],V[i]};
}
sort(all(edge));
vector<int> cnt(N,0);
for(auto &[w,u,v]:edge){
uni.merge(u,v);
cnt[u]++;
cnt[v]++;
if(cnt[u]>=3||cnt[v]>=3){
int pos=uni.root(u,uni.time);
uni.tree[pos].back()[2]=1;
}
}
}
int getMinimumFuelCapacity(int X, int Y) {
int ng=-1,ok=uni.time+1;
while(ok-ng>1){
int mid=(ok+ng)/2;
bool can=0;
if(uni.same(X,Y,mid)){
if(uni.isok(X,mid))can=1;
}
if(can)ok=mid;
else ng=mid;
}
if(ok==uni.time+1)return -1;
return edge[ok][0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
49 ms |
11448 KB |
Output is correct |
10 |
Correct |
57 ms |
14164 KB |
Output is correct |
11 |
Correct |
53 ms |
13904 KB |
Output is correct |
12 |
Correct |
58 ms |
14676 KB |
Output is correct |
13 |
Correct |
51 ms |
13360 KB |
Output is correct |
14 |
Correct |
139 ms |
11980 KB |
Output is correct |
15 |
Correct |
1014 ms |
18344 KB |
Output is correct |
16 |
Correct |
1012 ms |
17812 KB |
Output is correct |
17 |
Correct |
1063 ms |
18608 KB |
Output is correct |
18 |
Correct |
900 ms |
17296 KB |
Output is correct |
19 |
Correct |
591 ms |
8016 KB |
Output is correct |
20 |
Correct |
1014 ms |
19156 KB |
Output is correct |
21 |
Correct |
1101 ms |
18784 KB |
Output is correct |
22 |
Correct |
1026 ms |
19684 KB |
Output is correct |
23 |
Correct |
855 ms |
18488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
662 ms |
16808 KB |
Output is correct |
4 |
Correct |
681 ms |
17208 KB |
Output is correct |
5 |
Correct |
696 ms |
17324 KB |
Output is correct |
6 |
Correct |
640 ms |
17316 KB |
Output is correct |
7 |
Correct |
705 ms |
17348 KB |
Output is correct |
8 |
Correct |
693 ms |
16932 KB |
Output is correct |
9 |
Correct |
669 ms |
17096 KB |
Output is correct |
10 |
Correct |
676 ms |
16660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
440 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
2 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
49 ms |
11448 KB |
Output is correct |
11 |
Correct |
57 ms |
14164 KB |
Output is correct |
12 |
Correct |
53 ms |
13904 KB |
Output is correct |
13 |
Correct |
58 ms |
14676 KB |
Output is correct |
14 |
Correct |
51 ms |
13360 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
440 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
9 ms |
2140 KB |
Output is correct |
35 |
Correct |
54 ms |
14272 KB |
Output is correct |
36 |
Correct |
57 ms |
14256 KB |
Output is correct |
37 |
Correct |
58 ms |
14328 KB |
Output is correct |
38 |
Correct |
69 ms |
14192 KB |
Output is correct |
39 |
Correct |
57 ms |
13908 KB |
Output is correct |
40 |
Correct |
48 ms |
12628 KB |
Output is correct |
41 |
Correct |
71 ms |
14932 KB |
Output is correct |
42 |
Correct |
57 ms |
14420 KB |
Output is correct |
43 |
Correct |
51 ms |
13832 KB |
Output is correct |
44 |
Correct |
58 ms |
14408 KB |
Output is correct |
45 |
Correct |
120 ms |
15192 KB |
Output is correct |
46 |
Correct |
54 ms |
14240 KB |
Output is correct |
47 |
Correct |
61 ms |
14164 KB |
Output is correct |
48 |
Correct |
66 ms |
14212 KB |
Output is correct |
49 |
Correct |
85 ms |
8788 KB |
Output is correct |
50 |
Correct |
76 ms |
7868 KB |
Output is correct |
51 |
Correct |
102 ms |
12808 KB |
Output is correct |
52 |
Correct |
121 ms |
18260 KB |
Output is correct |
53 |
Correct |
130 ms |
20560 KB |
Output is correct |
54 |
Correct |
170 ms |
20052 KB |
Output is correct |
55 |
Correct |
57 ms |
13088 KB |
Output is correct |
56 |
Correct |
127 ms |
18064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
49 ms |
11448 KB |
Output is correct |
10 |
Correct |
57 ms |
14164 KB |
Output is correct |
11 |
Correct |
53 ms |
13904 KB |
Output is correct |
12 |
Correct |
58 ms |
14676 KB |
Output is correct |
13 |
Correct |
51 ms |
13360 KB |
Output is correct |
14 |
Correct |
139 ms |
11980 KB |
Output is correct |
15 |
Correct |
1014 ms |
18344 KB |
Output is correct |
16 |
Correct |
1012 ms |
17812 KB |
Output is correct |
17 |
Correct |
1063 ms |
18608 KB |
Output is correct |
18 |
Correct |
900 ms |
17296 KB |
Output is correct |
19 |
Correct |
662 ms |
16808 KB |
Output is correct |
20 |
Correct |
681 ms |
17208 KB |
Output is correct |
21 |
Correct |
696 ms |
17324 KB |
Output is correct |
22 |
Correct |
640 ms |
17316 KB |
Output is correct |
23 |
Correct |
705 ms |
17348 KB |
Output is correct |
24 |
Correct |
693 ms |
16932 KB |
Output is correct |
25 |
Correct |
669 ms |
17096 KB |
Output is correct |
26 |
Correct |
676 ms |
16660 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
440 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
9 ms |
2140 KB |
Output is correct |
37 |
Correct |
54 ms |
14272 KB |
Output is correct |
38 |
Correct |
57 ms |
14256 KB |
Output is correct |
39 |
Correct |
58 ms |
14328 KB |
Output is correct |
40 |
Correct |
69 ms |
14192 KB |
Output is correct |
41 |
Correct |
57 ms |
13908 KB |
Output is correct |
42 |
Correct |
48 ms |
12628 KB |
Output is correct |
43 |
Correct |
71 ms |
14932 KB |
Output is correct |
44 |
Correct |
57 ms |
14420 KB |
Output is correct |
45 |
Correct |
51 ms |
13832 KB |
Output is correct |
46 |
Correct |
58 ms |
14408 KB |
Output is correct |
47 |
Correct |
82 ms |
2500 KB |
Output is correct |
48 |
Correct |
970 ms |
18992 KB |
Output is correct |
49 |
Correct |
956 ms |
18816 KB |
Output is correct |
50 |
Correct |
1000 ms |
18880 KB |
Output is correct |
51 |
Correct |
1004 ms |
18712 KB |
Output is correct |
52 |
Correct |
1031 ms |
17892 KB |
Output is correct |
53 |
Correct |
1020 ms |
15192 KB |
Output is correct |
54 |
Correct |
1002 ms |
19644 KB |
Output is correct |
55 |
Correct |
1014 ms |
18848 KB |
Output is correct |
56 |
Correct |
718 ms |
17528 KB |
Output is correct |
57 |
Correct |
1142 ms |
19320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
49 ms |
11448 KB |
Output is correct |
11 |
Correct |
57 ms |
14164 KB |
Output is correct |
12 |
Correct |
53 ms |
13904 KB |
Output is correct |
13 |
Correct |
58 ms |
14676 KB |
Output is correct |
14 |
Correct |
51 ms |
13360 KB |
Output is correct |
15 |
Correct |
139 ms |
11980 KB |
Output is correct |
16 |
Correct |
1014 ms |
18344 KB |
Output is correct |
17 |
Correct |
1012 ms |
17812 KB |
Output is correct |
18 |
Correct |
1063 ms |
18608 KB |
Output is correct |
19 |
Correct |
900 ms |
17296 KB |
Output is correct |
20 |
Correct |
662 ms |
16808 KB |
Output is correct |
21 |
Correct |
681 ms |
17208 KB |
Output is correct |
22 |
Correct |
696 ms |
17324 KB |
Output is correct |
23 |
Correct |
640 ms |
17316 KB |
Output is correct |
24 |
Correct |
705 ms |
17348 KB |
Output is correct |
25 |
Correct |
693 ms |
16932 KB |
Output is correct |
26 |
Correct |
669 ms |
17096 KB |
Output is correct |
27 |
Correct |
676 ms |
16660 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
440 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
9 ms |
2140 KB |
Output is correct |
38 |
Correct |
54 ms |
14272 KB |
Output is correct |
39 |
Correct |
57 ms |
14256 KB |
Output is correct |
40 |
Correct |
58 ms |
14328 KB |
Output is correct |
41 |
Correct |
69 ms |
14192 KB |
Output is correct |
42 |
Correct |
57 ms |
13908 KB |
Output is correct |
43 |
Correct |
48 ms |
12628 KB |
Output is correct |
44 |
Correct |
71 ms |
14932 KB |
Output is correct |
45 |
Correct |
57 ms |
14420 KB |
Output is correct |
46 |
Correct |
51 ms |
13832 KB |
Output is correct |
47 |
Correct |
58 ms |
14408 KB |
Output is correct |
48 |
Correct |
82 ms |
2500 KB |
Output is correct |
49 |
Correct |
970 ms |
18992 KB |
Output is correct |
50 |
Correct |
956 ms |
18816 KB |
Output is correct |
51 |
Correct |
1000 ms |
18880 KB |
Output is correct |
52 |
Correct |
1004 ms |
18712 KB |
Output is correct |
53 |
Correct |
1031 ms |
17892 KB |
Output is correct |
54 |
Correct |
1020 ms |
15192 KB |
Output is correct |
55 |
Correct |
1002 ms |
19644 KB |
Output is correct |
56 |
Correct |
1014 ms |
18848 KB |
Output is correct |
57 |
Correct |
718 ms |
17528 KB |
Output is correct |
58 |
Correct |
1142 ms |
19320 KB |
Output is correct |
59 |
Correct |
591 ms |
8016 KB |
Output is correct |
60 |
Correct |
1014 ms |
19156 KB |
Output is correct |
61 |
Correct |
1101 ms |
18784 KB |
Output is correct |
62 |
Correct |
1026 ms |
19684 KB |
Output is correct |
63 |
Correct |
855 ms |
18488 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
1 ms |
348 KB |
Output is correct |
66 |
Correct |
1 ms |
348 KB |
Output is correct |
67 |
Correct |
1 ms |
344 KB |
Output is correct |
68 |
Correct |
1 ms |
348 KB |
Output is correct |
69 |
Correct |
2 ms |
604 KB |
Output is correct |
70 |
Correct |
1 ms |
604 KB |
Output is correct |
71 |
Correct |
2 ms |
600 KB |
Output is correct |
72 |
Correct |
1 ms |
344 KB |
Output is correct |
73 |
Correct |
1 ms |
600 KB |
Output is correct |
74 |
Correct |
120 ms |
15192 KB |
Output is correct |
75 |
Correct |
54 ms |
14240 KB |
Output is correct |
76 |
Correct |
61 ms |
14164 KB |
Output is correct |
77 |
Correct |
66 ms |
14212 KB |
Output is correct |
78 |
Correct |
85 ms |
8788 KB |
Output is correct |
79 |
Correct |
76 ms |
7868 KB |
Output is correct |
80 |
Correct |
102 ms |
12808 KB |
Output is correct |
81 |
Correct |
121 ms |
18260 KB |
Output is correct |
82 |
Correct |
130 ms |
20560 KB |
Output is correct |
83 |
Correct |
170 ms |
20052 KB |
Output is correct |
84 |
Correct |
57 ms |
13088 KB |
Output is correct |
85 |
Correct |
127 ms |
18064 KB |
Output is correct |
86 |
Correct |
239 ms |
6692 KB |
Output is correct |
87 |
Correct |
985 ms |
18856 KB |
Output is correct |
88 |
Correct |
1014 ms |
18736 KB |
Output is correct |
89 |
Correct |
1063 ms |
18016 KB |
Output is correct |
90 |
Correct |
863 ms |
13140 KB |
Output is correct |
91 |
Correct |
898 ms |
13720 KB |
Output is correct |
92 |
Correct |
1029 ms |
17288 KB |
Output is correct |
93 |
Correct |
1489 ms |
22276 KB |
Output is correct |
94 |
Correct |
1091 ms |
24248 KB |
Output is correct |
95 |
Correct |
1298 ms |
24008 KB |
Output is correct |
96 |
Correct |
733 ms |
17420 KB |
Output is correct |
97 |
Correct |
1110 ms |
20788 KB |
Output is correct |