#include "swap.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
int n, m;
vector<int> u_, v_, w, ver, var, par, P, p, her, sizes;
int get(int u)
{
if (u == par[u]) return u;
return get(par[u]);
}
void union_chains(int u, int v, int w)
{
int a = get(u), b = get(v);
if (a == b)
{
P[a] = min(P[a], w);
return;
}
if (sizes[a] < sizes[b]) swap(a, b), swap(u, v);
sizes[a] += sizes[b];
par[b] = a;
her[b] = max(her[b], w);
if (u == ver[a] && v == ver[b]) ver[a] = var[b];
else if (u == ver[a] && v == var[b]) ver[a] = ver[b];
else if (u == var[a] && v == ver[b]) var[a] = var[b];
else if (u == var[a] && v == var[b]) var[a] = ver[b];
else ver[a] = -1, var[a] = -1, P[a] = min(P[a], w);
}
int go(int u, int w)
{
if (par[u] == u || her[u] > w) return u;
return go(par[u], w);
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n = N, m = M;
vector<pair<int, pair<int, int>>> kox;
for (int i = 0; i < m; i++) kox.push_back({ W[i], {U[i], V[i]} });
sort(kox.begin(), kox.end());
ver = var = par = sizes = P = her = p = vector<int>(n);
for (int i = 0; i < n; i++) ver[i] = var[i] = par[i] = p[i] = i, sizes[i] = 1, her[i] = -1, P[i] = INT_MAX;
for (int i = 0; i < m; i++)
{
int u = kox[i].second.first, v = kox[i].second.second;
union_chains(u, v, kox[i].first);
}
}
int getMinimumFuelCapacity(int X, int Y) {
long long l = 0, r = 2e9;
while (l + 1 < r)
{
int mij = l + (r - l) / 2;
int a = go(X, mij), b = go(Y, mij);
if (a == b && P[a] <= mij) r = mij;
else l = mij;
}
return r == 2e9 ? -1 : r;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
35 ms |
5192 KB |
Output is correct |
10 |
Correct |
42 ms |
6208 KB |
Output is correct |
11 |
Correct |
45 ms |
6136 KB |
Output is correct |
12 |
Correct |
44 ms |
6452 KB |
Output is correct |
13 |
Correct |
44 ms |
6460 KB |
Output is correct |
14 |
Correct |
46 ms |
5316 KB |
Output is correct |
15 |
Correct |
171 ms |
7840 KB |
Output is correct |
16 |
Correct |
169 ms |
7664 KB |
Output is correct |
17 |
Correct |
188 ms |
8116 KB |
Output is correct |
18 |
Correct |
119 ms |
8120 KB |
Output is correct |
19 |
Correct |
122 ms |
4516 KB |
Output is correct |
20 |
Correct |
244 ms |
8096 KB |
Output is correct |
21 |
Correct |
214 ms |
8260 KB |
Output is correct |
22 |
Correct |
225 ms |
8600 KB |
Output is correct |
23 |
Correct |
133 ms |
8472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
135 ms |
8068 KB |
Output is correct |
4 |
Correct |
135 ms |
8204 KB |
Output is correct |
5 |
Correct |
145 ms |
8392 KB |
Output is correct |
6 |
Correct |
150 ms |
8144 KB |
Output is correct |
7 |
Correct |
138 ms |
8380 KB |
Output is correct |
8 |
Correct |
135 ms |
8112 KB |
Output is correct |
9 |
Correct |
138 ms |
8160 KB |
Output is correct |
10 |
Correct |
136 ms |
8136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
35 ms |
5192 KB |
Output is correct |
11 |
Correct |
42 ms |
6208 KB |
Output is correct |
12 |
Correct |
45 ms |
6136 KB |
Output is correct |
13 |
Correct |
44 ms |
6452 KB |
Output is correct |
14 |
Correct |
44 ms |
6460 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
312 KB |
Output is correct |
34 |
Correct |
6 ms |
1428 KB |
Output is correct |
35 |
Correct |
42 ms |
8360 KB |
Output is correct |
36 |
Correct |
44 ms |
8360 KB |
Output is correct |
37 |
Correct |
43 ms |
8348 KB |
Output is correct |
38 |
Correct |
41 ms |
8256 KB |
Output is correct |
39 |
Correct |
45 ms |
8212 KB |
Output is correct |
40 |
Correct |
38 ms |
7480 KB |
Output is correct |
41 |
Correct |
45 ms |
8604 KB |
Output is correct |
42 |
Correct |
42 ms |
8368 KB |
Output is correct |
43 |
Correct |
40 ms |
8364 KB |
Output is correct |
44 |
Correct |
44 ms |
8612 KB |
Output is correct |
45 |
Correct |
64 ms |
10688 KB |
Output is correct |
46 |
Correct |
41 ms |
8368 KB |
Output is correct |
47 |
Correct |
41 ms |
8256 KB |
Output is correct |
48 |
Correct |
46 ms |
8884 KB |
Output is correct |
49 |
Correct |
62 ms |
9932 KB |
Output is correct |
50 |
Correct |
51 ms |
7064 KB |
Output is correct |
51 |
Correct |
55 ms |
9152 KB |
Output is correct |
52 |
Correct |
74 ms |
12028 KB |
Output is correct |
53 |
Correct |
78 ms |
13116 KB |
Output is correct |
54 |
Correct |
88 ms |
14004 KB |
Output is correct |
55 |
Correct |
41 ms |
8348 KB |
Output is correct |
56 |
Correct |
74 ms |
12660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
456 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
35 ms |
5192 KB |
Output is correct |
10 |
Correct |
42 ms |
6208 KB |
Output is correct |
11 |
Correct |
45 ms |
6136 KB |
Output is correct |
12 |
Correct |
44 ms |
6452 KB |
Output is correct |
13 |
Correct |
44 ms |
6460 KB |
Output is correct |
14 |
Correct |
46 ms |
5316 KB |
Output is correct |
15 |
Correct |
171 ms |
7840 KB |
Output is correct |
16 |
Correct |
169 ms |
7664 KB |
Output is correct |
17 |
Correct |
188 ms |
8116 KB |
Output is correct |
18 |
Correct |
119 ms |
8120 KB |
Output is correct |
19 |
Correct |
135 ms |
8068 KB |
Output is correct |
20 |
Correct |
135 ms |
8204 KB |
Output is correct |
21 |
Correct |
145 ms |
8392 KB |
Output is correct |
22 |
Correct |
150 ms |
8144 KB |
Output is correct |
23 |
Correct |
138 ms |
8380 KB |
Output is correct |
24 |
Correct |
135 ms |
8112 KB |
Output is correct |
25 |
Correct |
138 ms |
8160 KB |
Output is correct |
26 |
Correct |
136 ms |
8136 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
6 ms |
1428 KB |
Output is correct |
37 |
Correct |
42 ms |
8360 KB |
Output is correct |
38 |
Correct |
44 ms |
8360 KB |
Output is correct |
39 |
Correct |
43 ms |
8348 KB |
Output is correct |
40 |
Correct |
41 ms |
8256 KB |
Output is correct |
41 |
Correct |
45 ms |
8212 KB |
Output is correct |
42 |
Correct |
38 ms |
7480 KB |
Output is correct |
43 |
Correct |
45 ms |
8604 KB |
Output is correct |
44 |
Correct |
42 ms |
8368 KB |
Output is correct |
45 |
Correct |
40 ms |
8364 KB |
Output is correct |
46 |
Correct |
44 ms |
8612 KB |
Output is correct |
47 |
Correct |
22 ms |
1684 KB |
Output is correct |
48 |
Correct |
214 ms |
12232 KB |
Output is correct |
49 |
Correct |
210 ms |
12256 KB |
Output is correct |
50 |
Correct |
209 ms |
12224 KB |
Output is correct |
51 |
Correct |
210 ms |
12224 KB |
Output is correct |
52 |
Correct |
195 ms |
11704 KB |
Output is correct |
53 |
Correct |
199 ms |
10904 KB |
Output is correct |
54 |
Correct |
219 ms |
12884 KB |
Output is correct |
55 |
Correct |
225 ms |
12224 KB |
Output is correct |
56 |
Correct |
142 ms |
12196 KB |
Output is correct |
57 |
Correct |
216 ms |
12940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
35 ms |
5192 KB |
Output is correct |
11 |
Correct |
42 ms |
6208 KB |
Output is correct |
12 |
Correct |
45 ms |
6136 KB |
Output is correct |
13 |
Correct |
44 ms |
6452 KB |
Output is correct |
14 |
Correct |
44 ms |
6460 KB |
Output is correct |
15 |
Correct |
46 ms |
5316 KB |
Output is correct |
16 |
Correct |
171 ms |
7840 KB |
Output is correct |
17 |
Correct |
169 ms |
7664 KB |
Output is correct |
18 |
Correct |
188 ms |
8116 KB |
Output is correct |
19 |
Correct |
119 ms |
8120 KB |
Output is correct |
20 |
Correct |
135 ms |
8068 KB |
Output is correct |
21 |
Correct |
135 ms |
8204 KB |
Output is correct |
22 |
Correct |
145 ms |
8392 KB |
Output is correct |
23 |
Correct |
150 ms |
8144 KB |
Output is correct |
24 |
Correct |
138 ms |
8380 KB |
Output is correct |
25 |
Correct |
135 ms |
8112 KB |
Output is correct |
26 |
Correct |
138 ms |
8160 KB |
Output is correct |
27 |
Correct |
136 ms |
8136 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
6 ms |
1428 KB |
Output is correct |
38 |
Correct |
42 ms |
8360 KB |
Output is correct |
39 |
Correct |
44 ms |
8360 KB |
Output is correct |
40 |
Correct |
43 ms |
8348 KB |
Output is correct |
41 |
Correct |
41 ms |
8256 KB |
Output is correct |
42 |
Correct |
45 ms |
8212 KB |
Output is correct |
43 |
Correct |
38 ms |
7480 KB |
Output is correct |
44 |
Correct |
45 ms |
8604 KB |
Output is correct |
45 |
Correct |
42 ms |
8368 KB |
Output is correct |
46 |
Correct |
40 ms |
8364 KB |
Output is correct |
47 |
Correct |
44 ms |
8612 KB |
Output is correct |
48 |
Correct |
22 ms |
1684 KB |
Output is correct |
49 |
Correct |
214 ms |
12232 KB |
Output is correct |
50 |
Correct |
210 ms |
12256 KB |
Output is correct |
51 |
Correct |
209 ms |
12224 KB |
Output is correct |
52 |
Correct |
210 ms |
12224 KB |
Output is correct |
53 |
Correct |
195 ms |
11704 KB |
Output is correct |
54 |
Correct |
199 ms |
10904 KB |
Output is correct |
55 |
Correct |
219 ms |
12884 KB |
Output is correct |
56 |
Correct |
225 ms |
12224 KB |
Output is correct |
57 |
Correct |
142 ms |
12196 KB |
Output is correct |
58 |
Correct |
216 ms |
12940 KB |
Output is correct |
59 |
Correct |
122 ms |
4516 KB |
Output is correct |
60 |
Correct |
244 ms |
8096 KB |
Output is correct |
61 |
Correct |
214 ms |
8260 KB |
Output is correct |
62 |
Correct |
225 ms |
8600 KB |
Output is correct |
63 |
Correct |
133 ms |
8472 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
2 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
1 ms |
312 KB |
Output is correct |
74 |
Correct |
64 ms |
10688 KB |
Output is correct |
75 |
Correct |
41 ms |
8368 KB |
Output is correct |
76 |
Correct |
41 ms |
8256 KB |
Output is correct |
77 |
Correct |
46 ms |
8884 KB |
Output is correct |
78 |
Correct |
62 ms |
9932 KB |
Output is correct |
79 |
Correct |
51 ms |
7064 KB |
Output is correct |
80 |
Correct |
55 ms |
9152 KB |
Output is correct |
81 |
Correct |
74 ms |
12028 KB |
Output is correct |
82 |
Correct |
78 ms |
13116 KB |
Output is correct |
83 |
Correct |
88 ms |
14004 KB |
Output is correct |
84 |
Correct |
41 ms |
8348 KB |
Output is correct |
85 |
Correct |
74 ms |
12660 KB |
Output is correct |
86 |
Correct |
56 ms |
4788 KB |
Output is correct |
87 |
Correct |
204 ms |
12228 KB |
Output is correct |
88 |
Correct |
211 ms |
12188 KB |
Output is correct |
89 |
Correct |
168 ms |
12320 KB |
Output is correct |
90 |
Correct |
185 ms |
13628 KB |
Output is correct |
91 |
Correct |
182 ms |
13420 KB |
Output is correct |
92 |
Correct |
180 ms |
12744 KB |
Output is correct |
93 |
Correct |
230 ms |
15828 KB |
Output is correct |
94 |
Correct |
217 ms |
16800 KB |
Output is correct |
95 |
Correct |
272 ms |
17848 KB |
Output is correct |
96 |
Correct |
142 ms |
12208 KB |
Output is correct |
97 |
Correct |
192 ms |
14524 KB |
Output is correct |