#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
int p[100001], pweight[100001][20], st[100001], en[100001], lineWeight[100001], twok[100001][20];
void init(int N){
iota(p, p+N, 0);
iota(st, st+N, 0);
iota(en, en+N, 0);
fill(lineWeight, lineWeight+N, 2e9);
memset(twok, -1, sizeof twok);
memset(pweight, -1, sizeof pweight);
}
int fs(int x){
if (p[x] == x) return x;
return p[x] = fs(p[x]);
}
void ms(int x, int y, int w){
int px = fs(x), py = fs(y);
if (px == py){
st[px] = en[px] = -1;
lineWeight[px] = min(lineWeight[px], w);
return;
}
p[py] = px; // px -> py
//cout << px << ' ' << py << ' ' << w << endl;
twok[py][0] = px;
pweight[py][0] = w;
if (st[px] != -1 && st[py] != -1){
if ((st[px] == x || en[px] == x) && (st[py] == y || en[py] == y)){
st[px] = (st[px] == x ? en[px] : st[px]);
en[px] = (st[py] == y ? en[py] : st[py]);
} else {
st[px] = en[px] = -1;
lineWeight[px] = min(lineWeight[px], w);
}
} else if (st[px] != -1){
st[px] = en[px] = -1;
lineWeight[px] = w;
} else {
lineWeight[px] = min(lineWeight[px], lineWeight[py]);
}
}
void init(int N, int M,
std::vector<int> U, std::vector<int> V, std::vector<int> W) {
init(N);
vector<tuple<int, int, int>> edges;
for (int i = 0; i < M; i++){
edges.push_back({W[i], U[i], V[i]});
}
sort(edges.begin(), edges.end());
for (auto [w, a, b] : edges){
ms(a, b, w);
}
for (int i = 1; i <= 19; i++){
for (int j = 0; j < N; j++){
if (twok[j][i-1] != -1){
twok[j][i] = twok[twok[j][i-1]][i-1];
pweight[j][i] = max(pweight[j][i-1], pweight[twok[j][i-1]][i-1]);
}
}
}
}
bool isOkay(int mid, int X, int Y){
for (int i = 19; i >= 0; i--){
if (twok[X][i] != -1 && pweight[X][i] <= mid) X = twok[X][i];
if (twok[Y][i] != -1 && pweight[Y][i] <= mid) Y = twok[Y][i];
}
if (X != Y) return false;
return lineWeight[X] != -1 && lineWeight[X] <= mid;
}
int getMinimumFuelCapacity(int X, int Y) {
int mini = 0, maxi = 1e9+10;
while (maxi - mini > 1){
int mid = (maxi + mini) / 2;
if (isOkay(mid, X, Y)) maxi = mid;
else mini = mid;
}
return (maxi==1e9+10?-1:maxi);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15956 KB |
Output is correct |
2 |
Correct |
7 ms |
15956 KB |
Output is correct |
3 |
Correct |
8 ms |
15956 KB |
Output is correct |
4 |
Correct |
6 ms |
15956 KB |
Output is correct |
5 |
Correct |
7 ms |
15964 KB |
Output is correct |
6 |
Correct |
7 ms |
15956 KB |
Output is correct |
7 |
Correct |
9 ms |
15972 KB |
Output is correct |
8 |
Correct |
8 ms |
15956 KB |
Output is correct |
9 |
Correct |
52 ms |
20720 KB |
Output is correct |
10 |
Correct |
61 ms |
21316 KB |
Output is correct |
11 |
Correct |
58 ms |
21260 KB |
Output is correct |
12 |
Correct |
63 ms |
21444 KB |
Output is correct |
13 |
Correct |
87 ms |
21432 KB |
Output is correct |
14 |
Correct |
99 ms |
20796 KB |
Output is correct |
15 |
Correct |
549 ms |
22952 KB |
Output is correct |
16 |
Correct |
547 ms |
22768 KB |
Output is correct |
17 |
Correct |
591 ms |
23004 KB |
Output is correct |
18 |
Correct |
1060 ms |
23000 KB |
Output is correct |
19 |
Correct |
366 ms |
20132 KB |
Output is correct |
20 |
Correct |
562 ms |
22876 KB |
Output is correct |
21 |
Correct |
540 ms |
22916 KB |
Output is correct |
22 |
Correct |
571 ms |
23104 KB |
Output is correct |
23 |
Correct |
955 ms |
23292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15956 KB |
Output is correct |
2 |
Correct |
7 ms |
15956 KB |
Output is correct |
3 |
Correct |
463 ms |
22788 KB |
Output is correct |
4 |
Correct |
473 ms |
23388 KB |
Output is correct |
5 |
Correct |
462 ms |
23464 KB |
Output is correct |
6 |
Correct |
434 ms |
23372 KB |
Output is correct |
7 |
Correct |
481 ms |
23492 KB |
Output is correct |
8 |
Correct |
516 ms |
23268 KB |
Output is correct |
9 |
Correct |
437 ms |
23364 KB |
Output is correct |
10 |
Correct |
480 ms |
23248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15956 KB |
Output is correct |
2 |
Correct |
7 ms |
15956 KB |
Output is correct |
3 |
Correct |
8 ms |
15956 KB |
Output is correct |
4 |
Correct |
6 ms |
15956 KB |
Output is correct |
5 |
Correct |
7 ms |
15964 KB |
Output is correct |
6 |
Correct |
7 ms |
15956 KB |
Output is correct |
7 |
Correct |
9 ms |
15972 KB |
Output is correct |
8 |
Correct |
8 ms |
15956 KB |
Output is correct |
9 |
Correct |
7 ms |
15964 KB |
Output is correct |
10 |
Correct |
8 ms |
16044 KB |
Output is correct |
11 |
Correct |
7 ms |
15956 KB |
Output is correct |
12 |
Correct |
10 ms |
15956 KB |
Output is correct |
13 |
Correct |
8 ms |
15932 KB |
Output is correct |
14 |
Correct |
8 ms |
15956 KB |
Output is correct |
15 |
Correct |
9 ms |
15952 KB |
Output is correct |
16 |
Correct |
8 ms |
15956 KB |
Output is correct |
17 |
Correct |
8 ms |
15956 KB |
Output is correct |
18 |
Correct |
8 ms |
15956 KB |
Output is correct |
19 |
Correct |
8 ms |
15956 KB |
Output is correct |
20 |
Correct |
7 ms |
15956 KB |
Output is correct |
21 |
Correct |
7 ms |
15956 KB |
Output is correct |
22 |
Correct |
7 ms |
16084 KB |
Output is correct |
23 |
Correct |
7 ms |
15940 KB |
Output is correct |
24 |
Correct |
8 ms |
16084 KB |
Output is correct |
25 |
Correct |
8 ms |
16084 KB |
Output is correct |
26 |
Correct |
8 ms |
16016 KB |
Output is correct |
27 |
Correct |
7 ms |
15956 KB |
Output is correct |
28 |
Correct |
10 ms |
16068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15964 KB |
Output is correct |
2 |
Correct |
7 ms |
15956 KB |
Output is correct |
3 |
Correct |
7 ms |
15956 KB |
Output is correct |
4 |
Correct |
8 ms |
15956 KB |
Output is correct |
5 |
Correct |
6 ms |
15956 KB |
Output is correct |
6 |
Correct |
7 ms |
15964 KB |
Output is correct |
7 |
Correct |
7 ms |
15956 KB |
Output is correct |
8 |
Correct |
9 ms |
15972 KB |
Output is correct |
9 |
Correct |
8 ms |
15956 KB |
Output is correct |
10 |
Correct |
52 ms |
20720 KB |
Output is correct |
11 |
Correct |
61 ms |
21316 KB |
Output is correct |
12 |
Correct |
58 ms |
21260 KB |
Output is correct |
13 |
Correct |
63 ms |
21444 KB |
Output is correct |
14 |
Correct |
87 ms |
21432 KB |
Output is correct |
15 |
Correct |
8 ms |
16044 KB |
Output is correct |
16 |
Correct |
7 ms |
15956 KB |
Output is correct |
17 |
Correct |
10 ms |
15956 KB |
Output is correct |
18 |
Correct |
8 ms |
15932 KB |
Output is correct |
19 |
Correct |
8 ms |
15956 KB |
Output is correct |
20 |
Correct |
9 ms |
15952 KB |
Output is correct |
21 |
Correct |
8 ms |
15956 KB |
Output is correct |
22 |
Correct |
8 ms |
15956 KB |
Output is correct |
23 |
Correct |
8 ms |
15956 KB |
Output is correct |
24 |
Correct |
8 ms |
15956 KB |
Output is correct |
25 |
Correct |
7 ms |
15956 KB |
Output is correct |
26 |
Correct |
7 ms |
15956 KB |
Output is correct |
27 |
Correct |
7 ms |
16084 KB |
Output is correct |
28 |
Correct |
7 ms |
15940 KB |
Output is correct |
29 |
Correct |
8 ms |
16084 KB |
Output is correct |
30 |
Correct |
8 ms |
16084 KB |
Output is correct |
31 |
Correct |
8 ms |
16016 KB |
Output is correct |
32 |
Correct |
7 ms |
15956 KB |
Output is correct |
33 |
Correct |
10 ms |
16068 KB |
Output is correct |
34 |
Correct |
14 ms |
17020 KB |
Output is correct |
35 |
Correct |
65 ms |
23352 KB |
Output is correct |
36 |
Correct |
62 ms |
23348 KB |
Output is correct |
37 |
Correct |
66 ms |
23356 KB |
Output is correct |
38 |
Correct |
74 ms |
23212 KB |
Output is correct |
39 |
Correct |
64 ms |
23236 KB |
Output is correct |
40 |
Correct |
62 ms |
22724 KB |
Output is correct |
41 |
Correct |
67 ms |
23540 KB |
Output is correct |
42 |
Correct |
67 ms |
23364 KB |
Output is correct |
43 |
Correct |
84 ms |
23364 KB |
Output is correct |
44 |
Correct |
92 ms |
23552 KB |
Output is correct |
45 |
Correct |
99 ms |
26944 KB |
Output is correct |
46 |
Correct |
63 ms |
23348 KB |
Output is correct |
47 |
Correct |
71 ms |
23336 KB |
Output is correct |
48 |
Correct |
82 ms |
23724 KB |
Output is correct |
49 |
Correct |
67 ms |
25564 KB |
Output is correct |
50 |
Correct |
68 ms |
22824 KB |
Output is correct |
51 |
Correct |
84 ms |
24324 KB |
Output is correct |
52 |
Correct |
88 ms |
27840 KB |
Output is correct |
53 |
Incorrect |
107 ms |
28608 KB |
Output isn't correct |
54 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15956 KB |
Output is correct |
2 |
Correct |
7 ms |
15956 KB |
Output is correct |
3 |
Correct |
8 ms |
15956 KB |
Output is correct |
4 |
Correct |
6 ms |
15956 KB |
Output is correct |
5 |
Correct |
7 ms |
15964 KB |
Output is correct |
6 |
Correct |
7 ms |
15956 KB |
Output is correct |
7 |
Correct |
9 ms |
15972 KB |
Output is correct |
8 |
Correct |
8 ms |
15956 KB |
Output is correct |
9 |
Correct |
52 ms |
20720 KB |
Output is correct |
10 |
Correct |
61 ms |
21316 KB |
Output is correct |
11 |
Correct |
58 ms |
21260 KB |
Output is correct |
12 |
Correct |
63 ms |
21444 KB |
Output is correct |
13 |
Correct |
87 ms |
21432 KB |
Output is correct |
14 |
Correct |
99 ms |
20796 KB |
Output is correct |
15 |
Correct |
549 ms |
22952 KB |
Output is correct |
16 |
Correct |
547 ms |
22768 KB |
Output is correct |
17 |
Correct |
591 ms |
23004 KB |
Output is correct |
18 |
Correct |
1060 ms |
23000 KB |
Output is correct |
19 |
Correct |
463 ms |
22788 KB |
Output is correct |
20 |
Correct |
473 ms |
23388 KB |
Output is correct |
21 |
Correct |
462 ms |
23464 KB |
Output is correct |
22 |
Correct |
434 ms |
23372 KB |
Output is correct |
23 |
Correct |
481 ms |
23492 KB |
Output is correct |
24 |
Correct |
516 ms |
23268 KB |
Output is correct |
25 |
Correct |
437 ms |
23364 KB |
Output is correct |
26 |
Correct |
480 ms |
23248 KB |
Output is correct |
27 |
Correct |
8 ms |
16044 KB |
Output is correct |
28 |
Correct |
7 ms |
15956 KB |
Output is correct |
29 |
Correct |
10 ms |
15956 KB |
Output is correct |
30 |
Correct |
8 ms |
15932 KB |
Output is correct |
31 |
Correct |
8 ms |
15956 KB |
Output is correct |
32 |
Correct |
9 ms |
15952 KB |
Output is correct |
33 |
Correct |
8 ms |
15956 KB |
Output is correct |
34 |
Correct |
8 ms |
15956 KB |
Output is correct |
35 |
Correct |
8 ms |
15956 KB |
Output is correct |
36 |
Correct |
14 ms |
17020 KB |
Output is correct |
37 |
Correct |
65 ms |
23352 KB |
Output is correct |
38 |
Correct |
62 ms |
23348 KB |
Output is correct |
39 |
Correct |
66 ms |
23356 KB |
Output is correct |
40 |
Correct |
74 ms |
23212 KB |
Output is correct |
41 |
Correct |
64 ms |
23236 KB |
Output is correct |
42 |
Correct |
62 ms |
22724 KB |
Output is correct |
43 |
Correct |
67 ms |
23540 KB |
Output is correct |
44 |
Correct |
67 ms |
23364 KB |
Output is correct |
45 |
Correct |
84 ms |
23364 KB |
Output is correct |
46 |
Correct |
92 ms |
23552 KB |
Output is correct |
47 |
Correct |
63 ms |
17312 KB |
Output is correct |
48 |
Correct |
574 ms |
27212 KB |
Output is correct |
49 |
Incorrect |
539 ms |
27188 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
15964 KB |
Output is correct |
2 |
Correct |
7 ms |
15956 KB |
Output is correct |
3 |
Correct |
7 ms |
15956 KB |
Output is correct |
4 |
Correct |
8 ms |
15956 KB |
Output is correct |
5 |
Correct |
6 ms |
15956 KB |
Output is correct |
6 |
Correct |
7 ms |
15964 KB |
Output is correct |
7 |
Correct |
7 ms |
15956 KB |
Output is correct |
8 |
Correct |
9 ms |
15972 KB |
Output is correct |
9 |
Correct |
8 ms |
15956 KB |
Output is correct |
10 |
Correct |
52 ms |
20720 KB |
Output is correct |
11 |
Correct |
61 ms |
21316 KB |
Output is correct |
12 |
Correct |
58 ms |
21260 KB |
Output is correct |
13 |
Correct |
63 ms |
21444 KB |
Output is correct |
14 |
Correct |
87 ms |
21432 KB |
Output is correct |
15 |
Correct |
99 ms |
20796 KB |
Output is correct |
16 |
Correct |
549 ms |
22952 KB |
Output is correct |
17 |
Correct |
547 ms |
22768 KB |
Output is correct |
18 |
Correct |
591 ms |
23004 KB |
Output is correct |
19 |
Correct |
1060 ms |
23000 KB |
Output is correct |
20 |
Correct |
463 ms |
22788 KB |
Output is correct |
21 |
Correct |
473 ms |
23388 KB |
Output is correct |
22 |
Correct |
462 ms |
23464 KB |
Output is correct |
23 |
Correct |
434 ms |
23372 KB |
Output is correct |
24 |
Correct |
481 ms |
23492 KB |
Output is correct |
25 |
Correct |
516 ms |
23268 KB |
Output is correct |
26 |
Correct |
437 ms |
23364 KB |
Output is correct |
27 |
Correct |
480 ms |
23248 KB |
Output is correct |
28 |
Correct |
8 ms |
16044 KB |
Output is correct |
29 |
Correct |
7 ms |
15956 KB |
Output is correct |
30 |
Correct |
10 ms |
15956 KB |
Output is correct |
31 |
Correct |
8 ms |
15932 KB |
Output is correct |
32 |
Correct |
8 ms |
15956 KB |
Output is correct |
33 |
Correct |
9 ms |
15952 KB |
Output is correct |
34 |
Correct |
8 ms |
15956 KB |
Output is correct |
35 |
Correct |
8 ms |
15956 KB |
Output is correct |
36 |
Correct |
8 ms |
15956 KB |
Output is correct |
37 |
Correct |
14 ms |
17020 KB |
Output is correct |
38 |
Correct |
65 ms |
23352 KB |
Output is correct |
39 |
Correct |
62 ms |
23348 KB |
Output is correct |
40 |
Correct |
66 ms |
23356 KB |
Output is correct |
41 |
Correct |
74 ms |
23212 KB |
Output is correct |
42 |
Correct |
64 ms |
23236 KB |
Output is correct |
43 |
Correct |
62 ms |
22724 KB |
Output is correct |
44 |
Correct |
67 ms |
23540 KB |
Output is correct |
45 |
Correct |
67 ms |
23364 KB |
Output is correct |
46 |
Correct |
84 ms |
23364 KB |
Output is correct |
47 |
Correct |
92 ms |
23552 KB |
Output is correct |
48 |
Correct |
63 ms |
17312 KB |
Output is correct |
49 |
Correct |
574 ms |
27212 KB |
Output is correct |
50 |
Incorrect |
539 ms |
27188 KB |
Output isn't correct |
51 |
Halted |
0 ms |
0 KB |
- |