#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];
vector<int> linNodes[100001];
void init(int N){
iota(p, p+N, 0);
iota(st, st+N, 0);
iota(en, en+N, 0);
fill(lineWeight, lineWeight+N, 2e9);
for (int i = 0; i < N; i++) linNodes[i].push_back(i);
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 && lineWeight[px] == 2e9){
st[px] = en[px] = -1;
for (auto i : linNodes[px]){
lineWeight[i] = min(lineWeight[i], w);
}
return;
}
if (linNodes[px].size() < linNodes[py].size()) {swap(x, y); swap(px, py);}
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]);
for (auto i : linNodes[py]){
linNodes[px].push_back(i);
}
} else {
st[px] = en[px] = -1;
for (auto i : linNodes[px]){
lineWeight[i] = min(lineWeight[i], w);
}
for (auto i : linNodes[py]){
lineWeight[i] = min(lineWeight[i], w);
}
}
} else if (st[px] != -1){
st[px] = en[px] = -1;
for (auto i : linNodes[px]){
lineWeight[i] = w;
}
} else if (st[py] != -1){
st[py] = en[py] = -1;
for (auto i : linNodes[py]){
lineWeight[i] = 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);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
18260 KB |
Output is correct |
2 |
Correct |
9 ms |
18260 KB |
Output is correct |
3 |
Correct |
11 ms |
18260 KB |
Output is correct |
4 |
Correct |
12 ms |
18244 KB |
Output is correct |
5 |
Correct |
9 ms |
18388 KB |
Output is correct |
6 |
Correct |
12 ms |
18388 KB |
Output is correct |
7 |
Correct |
9 ms |
18388 KB |
Output is correct |
8 |
Correct |
9 ms |
18388 KB |
Output is correct |
9 |
Correct |
75 ms |
28100 KB |
Output is correct |
10 |
Correct |
87 ms |
29744 KB |
Output is correct |
11 |
Correct |
85 ms |
29628 KB |
Output is correct |
12 |
Correct |
109 ms |
30312 KB |
Output is correct |
13 |
Correct |
82 ms |
27716 KB |
Output is correct |
14 |
Correct |
121 ms |
28036 KB |
Output is correct |
15 |
Correct |
560 ms |
31808 KB |
Output is correct |
16 |
Correct |
530 ms |
31260 KB |
Output is correct |
17 |
Correct |
553 ms |
32104 KB |
Output is correct |
18 |
Correct |
459 ms |
29180 KB |
Output is correct |
19 |
Correct |
368 ms |
23332 KB |
Output is correct |
20 |
Correct |
522 ms |
31940 KB |
Output is correct |
21 |
Correct |
535 ms |
31732 KB |
Output is correct |
22 |
Correct |
577 ms |
32504 KB |
Output is correct |
23 |
Correct |
461 ms |
29524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
18260 KB |
Output is correct |
2 |
Correct |
9 ms |
18260 KB |
Output is correct |
3 |
Correct |
472 ms |
28032 KB |
Output is correct |
4 |
Correct |
489 ms |
28396 KB |
Output is correct |
5 |
Correct |
533 ms |
28388 KB |
Output is correct |
6 |
Correct |
482 ms |
28412 KB |
Output is correct |
7 |
Correct |
493 ms |
28356 KB |
Output is correct |
8 |
Correct |
497 ms |
28064 KB |
Output is correct |
9 |
Correct |
459 ms |
28232 KB |
Output is correct |
10 |
Correct |
480 ms |
27924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
18260 KB |
Output is correct |
2 |
Correct |
9 ms |
18260 KB |
Output is correct |
3 |
Correct |
11 ms |
18260 KB |
Output is correct |
4 |
Correct |
12 ms |
18244 KB |
Output is correct |
5 |
Correct |
9 ms |
18388 KB |
Output is correct |
6 |
Correct |
12 ms |
18388 KB |
Output is correct |
7 |
Correct |
9 ms |
18388 KB |
Output is correct |
8 |
Correct |
9 ms |
18388 KB |
Output is correct |
9 |
Correct |
9 ms |
18260 KB |
Output is correct |
10 |
Correct |
11 ms |
18404 KB |
Output is correct |
11 |
Correct |
9 ms |
18388 KB |
Output is correct |
12 |
Correct |
10 ms |
18388 KB |
Output is correct |
13 |
Correct |
9 ms |
18348 KB |
Output is correct |
14 |
Correct |
10 ms |
18396 KB |
Output is correct |
15 |
Correct |
10 ms |
18388 KB |
Output is correct |
16 |
Correct |
9 ms |
18388 KB |
Output is correct |
17 |
Correct |
11 ms |
18388 KB |
Output is correct |
18 |
Correct |
9 ms |
18388 KB |
Output is correct |
19 |
Correct |
9 ms |
18388 KB |
Output is correct |
20 |
Correct |
10 ms |
18348 KB |
Output is correct |
21 |
Correct |
9 ms |
18388 KB |
Output is correct |
22 |
Correct |
10 ms |
18412 KB |
Output is correct |
23 |
Correct |
9 ms |
18388 KB |
Output is correct |
24 |
Correct |
10 ms |
18388 KB |
Output is correct |
25 |
Correct |
10 ms |
18420 KB |
Output is correct |
26 |
Correct |
10 ms |
18388 KB |
Output is correct |
27 |
Correct |
10 ms |
18424 KB |
Output is correct |
28 |
Correct |
10 ms |
18388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
18260 KB |
Output is correct |
2 |
Correct |
9 ms |
18260 KB |
Output is correct |
3 |
Correct |
9 ms |
18260 KB |
Output is correct |
4 |
Correct |
11 ms |
18260 KB |
Output is correct |
5 |
Correct |
12 ms |
18244 KB |
Output is correct |
6 |
Correct |
9 ms |
18388 KB |
Output is correct |
7 |
Correct |
12 ms |
18388 KB |
Output is correct |
8 |
Correct |
9 ms |
18388 KB |
Output is correct |
9 |
Correct |
9 ms |
18388 KB |
Output is correct |
10 |
Correct |
75 ms |
28100 KB |
Output is correct |
11 |
Correct |
87 ms |
29744 KB |
Output is correct |
12 |
Correct |
85 ms |
29628 KB |
Output is correct |
13 |
Correct |
109 ms |
30312 KB |
Output is correct |
14 |
Correct |
82 ms |
27716 KB |
Output is correct |
15 |
Correct |
11 ms |
18404 KB |
Output is correct |
16 |
Correct |
9 ms |
18388 KB |
Output is correct |
17 |
Correct |
10 ms |
18388 KB |
Output is correct |
18 |
Correct |
9 ms |
18348 KB |
Output is correct |
19 |
Correct |
10 ms |
18396 KB |
Output is correct |
20 |
Correct |
10 ms |
18388 KB |
Output is correct |
21 |
Correct |
9 ms |
18388 KB |
Output is correct |
22 |
Correct |
11 ms |
18388 KB |
Output is correct |
23 |
Correct |
9 ms |
18388 KB |
Output is correct |
24 |
Correct |
9 ms |
18388 KB |
Output is correct |
25 |
Correct |
10 ms |
18348 KB |
Output is correct |
26 |
Correct |
9 ms |
18388 KB |
Output is correct |
27 |
Correct |
10 ms |
18412 KB |
Output is correct |
28 |
Correct |
9 ms |
18388 KB |
Output is correct |
29 |
Correct |
10 ms |
18388 KB |
Output is correct |
30 |
Correct |
10 ms |
18420 KB |
Output is correct |
31 |
Correct |
10 ms |
18388 KB |
Output is correct |
32 |
Correct |
10 ms |
18424 KB |
Output is correct |
33 |
Correct |
10 ms |
18388 KB |
Output is correct |
34 |
Correct |
18 ms |
19540 KB |
Output is correct |
35 |
Correct |
97 ms |
29412 KB |
Output is correct |
36 |
Correct |
97 ms |
28920 KB |
Output is correct |
37 |
Correct |
102 ms |
28188 KB |
Output is correct |
38 |
Correct |
94 ms |
27492 KB |
Output is correct |
39 |
Correct |
87 ms |
26848 KB |
Output is correct |
40 |
Correct |
82 ms |
26224 KB |
Output is correct |
41 |
Correct |
104 ms |
30072 KB |
Output is correct |
42 |
Correct |
103 ms |
32136 KB |
Output is correct |
43 |
Correct |
85 ms |
28768 KB |
Output is correct |
44 |
Correct |
99 ms |
29128 KB |
Output is correct |
45 |
Correct |
116 ms |
31760 KB |
Output is correct |
46 |
Correct |
118 ms |
30808 KB |
Output is correct |
47 |
Correct |
115 ms |
29392 KB |
Output is correct |
48 |
Correct |
112 ms |
29144 KB |
Output is correct |
49 |
Correct |
67 ms |
28032 KB |
Output is correct |
50 |
Correct |
58 ms |
25420 KB |
Output is correct |
51 |
Correct |
88 ms |
28636 KB |
Output is correct |
52 |
Correct |
137 ms |
34792 KB |
Output is correct |
53 |
Correct |
151 ms |
34164 KB |
Output is correct |
54 |
Correct |
163 ms |
37352 KB |
Output is correct |
55 |
Correct |
94 ms |
28724 KB |
Output is correct |
56 |
Correct |
132 ms |
33824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
18260 KB |
Output is correct |
2 |
Correct |
9 ms |
18260 KB |
Output is correct |
3 |
Correct |
11 ms |
18260 KB |
Output is correct |
4 |
Correct |
12 ms |
18244 KB |
Output is correct |
5 |
Correct |
9 ms |
18388 KB |
Output is correct |
6 |
Correct |
12 ms |
18388 KB |
Output is correct |
7 |
Correct |
9 ms |
18388 KB |
Output is correct |
8 |
Correct |
9 ms |
18388 KB |
Output is correct |
9 |
Correct |
75 ms |
28100 KB |
Output is correct |
10 |
Correct |
87 ms |
29744 KB |
Output is correct |
11 |
Correct |
85 ms |
29628 KB |
Output is correct |
12 |
Correct |
109 ms |
30312 KB |
Output is correct |
13 |
Correct |
82 ms |
27716 KB |
Output is correct |
14 |
Correct |
121 ms |
28036 KB |
Output is correct |
15 |
Correct |
560 ms |
31808 KB |
Output is correct |
16 |
Correct |
530 ms |
31260 KB |
Output is correct |
17 |
Correct |
553 ms |
32104 KB |
Output is correct |
18 |
Correct |
459 ms |
29180 KB |
Output is correct |
19 |
Correct |
472 ms |
28032 KB |
Output is correct |
20 |
Correct |
489 ms |
28396 KB |
Output is correct |
21 |
Correct |
533 ms |
28388 KB |
Output is correct |
22 |
Correct |
482 ms |
28412 KB |
Output is correct |
23 |
Correct |
493 ms |
28356 KB |
Output is correct |
24 |
Correct |
497 ms |
28064 KB |
Output is correct |
25 |
Correct |
459 ms |
28232 KB |
Output is correct |
26 |
Correct |
480 ms |
27924 KB |
Output is correct |
27 |
Correct |
11 ms |
18404 KB |
Output is correct |
28 |
Correct |
9 ms |
18388 KB |
Output is correct |
29 |
Correct |
10 ms |
18388 KB |
Output is correct |
30 |
Correct |
9 ms |
18348 KB |
Output is correct |
31 |
Correct |
10 ms |
18396 KB |
Output is correct |
32 |
Correct |
10 ms |
18388 KB |
Output is correct |
33 |
Correct |
9 ms |
18388 KB |
Output is correct |
34 |
Correct |
11 ms |
18388 KB |
Output is correct |
35 |
Correct |
9 ms |
18388 KB |
Output is correct |
36 |
Correct |
18 ms |
19540 KB |
Output is correct |
37 |
Correct |
97 ms |
29412 KB |
Output is correct |
38 |
Correct |
97 ms |
28920 KB |
Output is correct |
39 |
Correct |
102 ms |
28188 KB |
Output is correct |
40 |
Correct |
94 ms |
27492 KB |
Output is correct |
41 |
Correct |
87 ms |
26848 KB |
Output is correct |
42 |
Correct |
82 ms |
26224 KB |
Output is correct |
43 |
Correct |
104 ms |
30072 KB |
Output is correct |
44 |
Correct |
103 ms |
32136 KB |
Output is correct |
45 |
Correct |
85 ms |
28768 KB |
Output is correct |
46 |
Correct |
99 ms |
29128 KB |
Output is correct |
47 |
Correct |
58 ms |
20076 KB |
Output is correct |
48 |
Correct |
523 ms |
35396 KB |
Output is correct |
49 |
Correct |
533 ms |
34592 KB |
Output is correct |
50 |
Correct |
525 ms |
33888 KB |
Output is correct |
51 |
Correct |
527 ms |
33220 KB |
Output is correct |
52 |
Correct |
501 ms |
32192 KB |
Output is correct |
53 |
Correct |
516 ms |
30388 KB |
Output is correct |
54 |
Correct |
543 ms |
36372 KB |
Output is correct |
55 |
Correct |
528 ms |
35948 KB |
Output is correct |
56 |
Correct |
471 ms |
32640 KB |
Output is correct |
57 |
Correct |
518 ms |
33028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
18260 KB |
Output is correct |
2 |
Correct |
9 ms |
18260 KB |
Output is correct |
3 |
Correct |
9 ms |
18260 KB |
Output is correct |
4 |
Correct |
11 ms |
18260 KB |
Output is correct |
5 |
Correct |
12 ms |
18244 KB |
Output is correct |
6 |
Correct |
9 ms |
18388 KB |
Output is correct |
7 |
Correct |
12 ms |
18388 KB |
Output is correct |
8 |
Correct |
9 ms |
18388 KB |
Output is correct |
9 |
Correct |
9 ms |
18388 KB |
Output is correct |
10 |
Correct |
75 ms |
28100 KB |
Output is correct |
11 |
Correct |
87 ms |
29744 KB |
Output is correct |
12 |
Correct |
85 ms |
29628 KB |
Output is correct |
13 |
Correct |
109 ms |
30312 KB |
Output is correct |
14 |
Correct |
82 ms |
27716 KB |
Output is correct |
15 |
Correct |
121 ms |
28036 KB |
Output is correct |
16 |
Correct |
560 ms |
31808 KB |
Output is correct |
17 |
Correct |
530 ms |
31260 KB |
Output is correct |
18 |
Correct |
553 ms |
32104 KB |
Output is correct |
19 |
Correct |
459 ms |
29180 KB |
Output is correct |
20 |
Correct |
472 ms |
28032 KB |
Output is correct |
21 |
Correct |
489 ms |
28396 KB |
Output is correct |
22 |
Correct |
533 ms |
28388 KB |
Output is correct |
23 |
Correct |
482 ms |
28412 KB |
Output is correct |
24 |
Correct |
493 ms |
28356 KB |
Output is correct |
25 |
Correct |
497 ms |
28064 KB |
Output is correct |
26 |
Correct |
459 ms |
28232 KB |
Output is correct |
27 |
Correct |
480 ms |
27924 KB |
Output is correct |
28 |
Correct |
11 ms |
18404 KB |
Output is correct |
29 |
Correct |
9 ms |
18388 KB |
Output is correct |
30 |
Correct |
10 ms |
18388 KB |
Output is correct |
31 |
Correct |
9 ms |
18348 KB |
Output is correct |
32 |
Correct |
10 ms |
18396 KB |
Output is correct |
33 |
Correct |
10 ms |
18388 KB |
Output is correct |
34 |
Correct |
9 ms |
18388 KB |
Output is correct |
35 |
Correct |
11 ms |
18388 KB |
Output is correct |
36 |
Correct |
9 ms |
18388 KB |
Output is correct |
37 |
Correct |
18 ms |
19540 KB |
Output is correct |
38 |
Correct |
97 ms |
29412 KB |
Output is correct |
39 |
Correct |
97 ms |
28920 KB |
Output is correct |
40 |
Correct |
102 ms |
28188 KB |
Output is correct |
41 |
Correct |
94 ms |
27492 KB |
Output is correct |
42 |
Correct |
87 ms |
26848 KB |
Output is correct |
43 |
Correct |
82 ms |
26224 KB |
Output is correct |
44 |
Correct |
104 ms |
30072 KB |
Output is correct |
45 |
Correct |
103 ms |
32136 KB |
Output is correct |
46 |
Correct |
85 ms |
28768 KB |
Output is correct |
47 |
Correct |
99 ms |
29128 KB |
Output is correct |
48 |
Correct |
58 ms |
20076 KB |
Output is correct |
49 |
Correct |
523 ms |
35396 KB |
Output is correct |
50 |
Correct |
533 ms |
34592 KB |
Output is correct |
51 |
Correct |
525 ms |
33888 KB |
Output is correct |
52 |
Correct |
527 ms |
33220 KB |
Output is correct |
53 |
Correct |
501 ms |
32192 KB |
Output is correct |
54 |
Correct |
516 ms |
30388 KB |
Output is correct |
55 |
Correct |
543 ms |
36372 KB |
Output is correct |
56 |
Correct |
528 ms |
35948 KB |
Output is correct |
57 |
Correct |
471 ms |
32640 KB |
Output is correct |
58 |
Correct |
518 ms |
33028 KB |
Output is correct |
59 |
Correct |
368 ms |
23332 KB |
Output is correct |
60 |
Correct |
522 ms |
31940 KB |
Output is correct |
61 |
Correct |
535 ms |
31732 KB |
Output is correct |
62 |
Correct |
577 ms |
32504 KB |
Output is correct |
63 |
Correct |
461 ms |
29524 KB |
Output is correct |
64 |
Correct |
9 ms |
18388 KB |
Output is correct |
65 |
Correct |
10 ms |
18348 KB |
Output is correct |
66 |
Correct |
9 ms |
18388 KB |
Output is correct |
67 |
Correct |
10 ms |
18412 KB |
Output is correct |
68 |
Correct |
9 ms |
18388 KB |
Output is correct |
69 |
Correct |
10 ms |
18388 KB |
Output is correct |
70 |
Correct |
10 ms |
18420 KB |
Output is correct |
71 |
Correct |
10 ms |
18388 KB |
Output is correct |
72 |
Correct |
10 ms |
18424 KB |
Output is correct |
73 |
Correct |
10 ms |
18388 KB |
Output is correct |
74 |
Correct |
116 ms |
31760 KB |
Output is correct |
75 |
Correct |
118 ms |
30808 KB |
Output is correct |
76 |
Correct |
115 ms |
29392 KB |
Output is correct |
77 |
Correct |
112 ms |
29144 KB |
Output is correct |
78 |
Correct |
67 ms |
28032 KB |
Output is correct |
79 |
Correct |
58 ms |
25420 KB |
Output is correct |
80 |
Correct |
88 ms |
28636 KB |
Output is correct |
81 |
Correct |
137 ms |
34792 KB |
Output is correct |
82 |
Correct |
151 ms |
34164 KB |
Output is correct |
83 |
Correct |
163 ms |
37352 KB |
Output is correct |
84 |
Correct |
94 ms |
28724 KB |
Output is correct |
85 |
Correct |
132 ms |
33824 KB |
Output is correct |
86 |
Correct |
219 ms |
23824 KB |
Output is correct |
87 |
Correct |
812 ms |
34260 KB |
Output is correct |
88 |
Correct |
845 ms |
34164 KB |
Output is correct |
89 |
Correct |
840 ms |
32492 KB |
Output is correct |
90 |
Correct |
752 ms |
31724 KB |
Output is correct |
91 |
Correct |
742 ms |
31900 KB |
Output is correct |
92 |
Correct |
802 ms |
32264 KB |
Output is correct |
93 |
Correct |
857 ms |
38004 KB |
Output is correct |
94 |
Correct |
846 ms |
37892 KB |
Output is correct |
95 |
Correct |
865 ms |
41404 KB |
Output is correct |
96 |
Correct |
789 ms |
32648 KB |
Output is correct |
97 |
Correct |
825 ms |
36164 KB |
Output is correct |