#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
struct node {
int endP[2], par, size, val;
} comp[MAXN];
int wpar[MAXN], depth[MAXN];
vector <int> adj[MAXN];
int root(int u) {
while (comp[u].par >= 0) u = comp[u].par;
return u;
}
bool join(int u, int v, int w) {
int x = root(u), y = root(v);
if (x == y) {
if (comp[x].val < 0) comp[x].val = w;
return false;
}
if (comp[x].size < comp[y].size) {
swap(x, y); swap(u, v);
}
comp[x].size += comp[y].size; comp[y].par = x;
wpar[y] = w; adj[x].push_back(y);
if (comp[x].val < 0 && comp[y].val < 0 &&
(u == comp[x].endP[0] || u == comp[x].endP[1]) &&
(v == comp[y].endP[0] || v == comp[y].endP[1])) {
if (u == comp[x].endP[0])
comp[x].endP[0] = comp[x].endP[1];
if (v == comp[y].endP[0])
comp[x].endP[1] = comp[y].endP[1];
else comp[x].endP[1] = comp[y].endP[0];
} else if (comp[x].val < 0) comp[x].val = w;
return true;
}
void DFS(int u) {
for (int v : adj[u]) {
depth[v] = depth[u] + 1; DFS(v);
}
}
void init(int N, int M, vector <int> U,
vector <int> V, vector <int> W) {
vector <int> sorted(M);
iota(sorted.begin(), sorted.end(), 0);
sort(sorted.begin(), sorted.end(),
[&](int i, int j) {return W[i] < W[j];});
for (int i = 0; i < N; i++) {
comp[i].endP[0] = comp[i].endP[1] = i;
comp[i].par = -1; comp[i].size = 1;
comp[i].val = -1;
}
for (int i : sorted) join(U[i], V[i], W[i]);
for (int i = 0; i < N; i++)
if (comp[i].par < 0) DFS(i);
}
int getMinimumFuelCapacity(int u, int v) {
if (root(u) != root(v)) return -1;
int res = 0;
while (u != v) {
if (depth[u] < depth[v]) swap(u, v);
res = max(res, wpar[u]); u = comp[u].par;
}
while (u >= 0 && comp[u].val < 0) {
res = max(res, wpar[u]); u = comp[u].par;
}
if (u < 0) return -1;
return max(res, comp[u].val);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
51 ms |
7932 KB |
Output is correct |
10 |
Correct |
62 ms |
9152 KB |
Output is correct |
11 |
Correct |
62 ms |
9016 KB |
Output is correct |
12 |
Correct |
70 ms |
9460 KB |
Output is correct |
13 |
Correct |
54 ms |
8536 KB |
Output is correct |
14 |
Correct |
63 ms |
8040 KB |
Output is correct |
15 |
Correct |
168 ms |
10724 KB |
Output is correct |
16 |
Correct |
169 ms |
10740 KB |
Output is correct |
17 |
Correct |
161 ms |
11128 KB |
Output is correct |
18 |
Correct |
140 ms |
10220 KB |
Output is correct |
19 |
Correct |
79 ms |
7156 KB |
Output is correct |
20 |
Correct |
159 ms |
11740 KB |
Output is correct |
21 |
Correct |
163 ms |
11792 KB |
Output is correct |
22 |
Correct |
177 ms |
12144 KB |
Output is correct |
23 |
Correct |
143 ms |
11492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
117 ms |
10948 KB |
Output is correct |
4 |
Correct |
122 ms |
10988 KB |
Output is correct |
5 |
Correct |
122 ms |
11224 KB |
Output is correct |
6 |
Correct |
116 ms |
10960 KB |
Output is correct |
7 |
Correct |
122 ms |
11196 KB |
Output is correct |
8 |
Correct |
119 ms |
10984 KB |
Output is correct |
9 |
Correct |
120 ms |
11068 KB |
Output is correct |
10 |
Correct |
117 ms |
10984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
3 ms |
2636 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
2 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2636 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2636 KB |
Output is correct |
21 |
Correct |
3 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
3 ms |
2764 KB |
Output is correct |
25 |
Correct |
3 ms |
2764 KB |
Output is correct |
26 |
Correct |
3 ms |
2696 KB |
Output is correct |
27 |
Correct |
2 ms |
2636 KB |
Output is correct |
28 |
Correct |
4 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
51 ms |
7932 KB |
Output is correct |
11 |
Correct |
62 ms |
9152 KB |
Output is correct |
12 |
Correct |
62 ms |
9016 KB |
Output is correct |
13 |
Correct |
70 ms |
9460 KB |
Output is correct |
14 |
Correct |
54 ms |
8536 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2636 KB |
Output is correct |
17 |
Correct |
2 ms |
2636 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
2 ms |
2640 KB |
Output is correct |
21 |
Correct |
2 ms |
2636 KB |
Output is correct |
22 |
Correct |
2 ms |
2636 KB |
Output is correct |
23 |
Correct |
2 ms |
2636 KB |
Output is correct |
24 |
Correct |
2 ms |
2636 KB |
Output is correct |
25 |
Correct |
2 ms |
2636 KB |
Output is correct |
26 |
Correct |
3 ms |
2636 KB |
Output is correct |
27 |
Correct |
3 ms |
2636 KB |
Output is correct |
28 |
Correct |
2 ms |
2636 KB |
Output is correct |
29 |
Correct |
3 ms |
2764 KB |
Output is correct |
30 |
Correct |
3 ms |
2764 KB |
Output is correct |
31 |
Correct |
3 ms |
2696 KB |
Output is correct |
32 |
Correct |
2 ms |
2636 KB |
Output is correct |
33 |
Correct |
4 ms |
2764 KB |
Output is correct |
34 |
Correct |
10 ms |
3804 KB |
Output is correct |
35 |
Correct |
65 ms |
11232 KB |
Output is correct |
36 |
Correct |
66 ms |
11204 KB |
Output is correct |
37 |
Correct |
68 ms |
11204 KB |
Output is correct |
38 |
Correct |
80 ms |
11104 KB |
Output is correct |
39 |
Correct |
65 ms |
10968 KB |
Output is correct |
40 |
Correct |
60 ms |
10236 KB |
Output is correct |
41 |
Correct |
75 ms |
11576 KB |
Output is correct |
42 |
Correct |
77 ms |
11256 KB |
Output is correct |
43 |
Correct |
54 ms |
10428 KB |
Output is correct |
44 |
Correct |
70 ms |
11320 KB |
Output is correct |
45 |
Correct |
90 ms |
12736 KB |
Output is correct |
46 |
Correct |
70 ms |
11236 KB |
Output is correct |
47 |
Correct |
74 ms |
11244 KB |
Output is correct |
48 |
Correct |
85 ms |
11564 KB |
Output is correct |
49 |
Correct |
77 ms |
9760 KB |
Output is correct |
50 |
Correct |
63 ms |
8540 KB |
Output is correct |
51 |
Correct |
81 ms |
11312 KB |
Output is correct |
52 |
Correct |
137 ms |
14536 KB |
Output is correct |
53 |
Correct |
119 ms |
15252 KB |
Output is correct |
54 |
Correct |
134 ms |
16112 KB |
Output is correct |
55 |
Correct |
54 ms |
10524 KB |
Output is correct |
56 |
Correct |
113 ms |
14832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
51 ms |
7932 KB |
Output is correct |
10 |
Correct |
62 ms |
9152 KB |
Output is correct |
11 |
Correct |
62 ms |
9016 KB |
Output is correct |
12 |
Correct |
70 ms |
9460 KB |
Output is correct |
13 |
Correct |
54 ms |
8536 KB |
Output is correct |
14 |
Correct |
63 ms |
8040 KB |
Output is correct |
15 |
Correct |
168 ms |
10724 KB |
Output is correct |
16 |
Correct |
169 ms |
10740 KB |
Output is correct |
17 |
Correct |
161 ms |
11128 KB |
Output is correct |
18 |
Correct |
140 ms |
10220 KB |
Output is correct |
19 |
Correct |
117 ms |
10948 KB |
Output is correct |
20 |
Correct |
122 ms |
10988 KB |
Output is correct |
21 |
Correct |
122 ms |
11224 KB |
Output is correct |
22 |
Correct |
116 ms |
10960 KB |
Output is correct |
23 |
Correct |
122 ms |
11196 KB |
Output is correct |
24 |
Correct |
119 ms |
10984 KB |
Output is correct |
25 |
Correct |
120 ms |
11068 KB |
Output is correct |
26 |
Correct |
117 ms |
10984 KB |
Output is correct |
27 |
Correct |
3 ms |
2636 KB |
Output is correct |
28 |
Correct |
2 ms |
2636 KB |
Output is correct |
29 |
Correct |
2 ms |
2636 KB |
Output is correct |
30 |
Correct |
2 ms |
2636 KB |
Output is correct |
31 |
Correct |
2 ms |
2636 KB |
Output is correct |
32 |
Correct |
2 ms |
2640 KB |
Output is correct |
33 |
Correct |
2 ms |
2636 KB |
Output is correct |
34 |
Correct |
2 ms |
2636 KB |
Output is correct |
35 |
Correct |
2 ms |
2636 KB |
Output is correct |
36 |
Correct |
10 ms |
3804 KB |
Output is correct |
37 |
Correct |
65 ms |
11232 KB |
Output is correct |
38 |
Correct |
66 ms |
11204 KB |
Output is correct |
39 |
Correct |
68 ms |
11204 KB |
Output is correct |
40 |
Correct |
80 ms |
11104 KB |
Output is correct |
41 |
Correct |
65 ms |
10968 KB |
Output is correct |
42 |
Correct |
60 ms |
10236 KB |
Output is correct |
43 |
Correct |
75 ms |
11576 KB |
Output is correct |
44 |
Correct |
77 ms |
11256 KB |
Output is correct |
45 |
Correct |
54 ms |
10428 KB |
Output is correct |
46 |
Correct |
70 ms |
11320 KB |
Output is correct |
47 |
Correct |
18 ms |
4204 KB |
Output is correct |
48 |
Correct |
166 ms |
15712 KB |
Output is correct |
49 |
Correct |
163 ms |
15692 KB |
Output is correct |
50 |
Correct |
164 ms |
15788 KB |
Output is correct |
51 |
Correct |
165 ms |
15664 KB |
Output is correct |
52 |
Correct |
156 ms |
15148 KB |
Output is correct |
53 |
Correct |
134 ms |
13932 KB |
Output is correct |
54 |
Correct |
174 ms |
16572 KB |
Output is correct |
55 |
Correct |
167 ms |
15680 KB |
Output is correct |
56 |
Correct |
158 ms |
15004 KB |
Output is correct |
57 |
Correct |
163 ms |
16416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
2 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
2 ms |
2636 KB |
Output is correct |
9 |
Correct |
2 ms |
2636 KB |
Output is correct |
10 |
Correct |
51 ms |
7932 KB |
Output is correct |
11 |
Correct |
62 ms |
9152 KB |
Output is correct |
12 |
Correct |
62 ms |
9016 KB |
Output is correct |
13 |
Correct |
70 ms |
9460 KB |
Output is correct |
14 |
Correct |
54 ms |
8536 KB |
Output is correct |
15 |
Correct |
63 ms |
8040 KB |
Output is correct |
16 |
Correct |
168 ms |
10724 KB |
Output is correct |
17 |
Correct |
169 ms |
10740 KB |
Output is correct |
18 |
Correct |
161 ms |
11128 KB |
Output is correct |
19 |
Correct |
140 ms |
10220 KB |
Output is correct |
20 |
Correct |
117 ms |
10948 KB |
Output is correct |
21 |
Correct |
122 ms |
10988 KB |
Output is correct |
22 |
Correct |
122 ms |
11224 KB |
Output is correct |
23 |
Correct |
116 ms |
10960 KB |
Output is correct |
24 |
Correct |
122 ms |
11196 KB |
Output is correct |
25 |
Correct |
119 ms |
10984 KB |
Output is correct |
26 |
Correct |
120 ms |
11068 KB |
Output is correct |
27 |
Correct |
117 ms |
10984 KB |
Output is correct |
28 |
Correct |
3 ms |
2636 KB |
Output is correct |
29 |
Correct |
2 ms |
2636 KB |
Output is correct |
30 |
Correct |
2 ms |
2636 KB |
Output is correct |
31 |
Correct |
2 ms |
2636 KB |
Output is correct |
32 |
Correct |
2 ms |
2636 KB |
Output is correct |
33 |
Correct |
2 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2636 KB |
Output is correct |
35 |
Correct |
2 ms |
2636 KB |
Output is correct |
36 |
Correct |
2 ms |
2636 KB |
Output is correct |
37 |
Correct |
10 ms |
3804 KB |
Output is correct |
38 |
Correct |
65 ms |
11232 KB |
Output is correct |
39 |
Correct |
66 ms |
11204 KB |
Output is correct |
40 |
Correct |
68 ms |
11204 KB |
Output is correct |
41 |
Correct |
80 ms |
11104 KB |
Output is correct |
42 |
Correct |
65 ms |
10968 KB |
Output is correct |
43 |
Correct |
60 ms |
10236 KB |
Output is correct |
44 |
Correct |
75 ms |
11576 KB |
Output is correct |
45 |
Correct |
77 ms |
11256 KB |
Output is correct |
46 |
Correct |
54 ms |
10428 KB |
Output is correct |
47 |
Correct |
70 ms |
11320 KB |
Output is correct |
48 |
Correct |
18 ms |
4204 KB |
Output is correct |
49 |
Correct |
166 ms |
15712 KB |
Output is correct |
50 |
Correct |
163 ms |
15692 KB |
Output is correct |
51 |
Correct |
164 ms |
15788 KB |
Output is correct |
52 |
Correct |
165 ms |
15664 KB |
Output is correct |
53 |
Correct |
156 ms |
15148 KB |
Output is correct |
54 |
Correct |
134 ms |
13932 KB |
Output is correct |
55 |
Correct |
174 ms |
16572 KB |
Output is correct |
56 |
Correct |
167 ms |
15680 KB |
Output is correct |
57 |
Correct |
158 ms |
15004 KB |
Output is correct |
58 |
Correct |
163 ms |
16416 KB |
Output is correct |
59 |
Correct |
79 ms |
7156 KB |
Output is correct |
60 |
Correct |
159 ms |
11740 KB |
Output is correct |
61 |
Correct |
163 ms |
11792 KB |
Output is correct |
62 |
Correct |
177 ms |
12144 KB |
Output is correct |
63 |
Correct |
143 ms |
11492 KB |
Output is correct |
64 |
Correct |
2 ms |
2636 KB |
Output is correct |
65 |
Correct |
2 ms |
2636 KB |
Output is correct |
66 |
Correct |
3 ms |
2636 KB |
Output is correct |
67 |
Correct |
3 ms |
2636 KB |
Output is correct |
68 |
Correct |
2 ms |
2636 KB |
Output is correct |
69 |
Correct |
3 ms |
2764 KB |
Output is correct |
70 |
Correct |
3 ms |
2764 KB |
Output is correct |
71 |
Correct |
3 ms |
2696 KB |
Output is correct |
72 |
Correct |
2 ms |
2636 KB |
Output is correct |
73 |
Correct |
4 ms |
2764 KB |
Output is correct |
74 |
Correct |
90 ms |
12736 KB |
Output is correct |
75 |
Correct |
70 ms |
11236 KB |
Output is correct |
76 |
Correct |
74 ms |
11244 KB |
Output is correct |
77 |
Correct |
85 ms |
11564 KB |
Output is correct |
78 |
Correct |
77 ms |
9760 KB |
Output is correct |
79 |
Correct |
63 ms |
8540 KB |
Output is correct |
80 |
Correct |
81 ms |
11312 KB |
Output is correct |
81 |
Correct |
137 ms |
14536 KB |
Output is correct |
82 |
Correct |
119 ms |
15252 KB |
Output is correct |
83 |
Correct |
134 ms |
16112 KB |
Output is correct |
84 |
Correct |
54 ms |
10524 KB |
Output is correct |
85 |
Correct |
113 ms |
14832 KB |
Output is correct |
86 |
Correct |
51 ms |
7236 KB |
Output is correct |
87 |
Correct |
171 ms |
15780 KB |
Output is correct |
88 |
Correct |
166 ms |
15768 KB |
Output is correct |
89 |
Correct |
147 ms |
15536 KB |
Output is correct |
90 |
Correct |
158 ms |
13556 KB |
Output is correct |
91 |
Correct |
153 ms |
13832 KB |
Output is correct |
92 |
Correct |
159 ms |
15700 KB |
Output is correct |
93 |
Correct |
205 ms |
18508 KB |
Output is correct |
94 |
Correct |
221 ms |
19184 KB |
Output is correct |
95 |
Correct |
232 ms |
19932 KB |
Output is correct |
96 |
Correct |
162 ms |
15004 KB |
Output is correct |
97 |
Correct |
183 ms |
17596 KB |
Output is correct |