#include "swap.h"
#include <bits/stdc++.h>
#define ii pair<int, int>
#define iii pair<int, ii>
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 5;
int n, m, par[N], p1[N], p2[N], past[N], cur[N];
vector <iii> edg;
int root(int u)
{
return (par[u] < 0) ? u : root(par[u]);
}
bool check(int u, int v, int mid)
{
while (par[u] > 0 && past[u] <= mid) u = par[u];
while (par[v] > 0 && past[v] <= mid) v = par[v];
if(u != v) return 0;
if(cur[u] && cur[u] <= mid) return 1;
return 0;
}
void join(int u, int v, int w)
{
int r1 = u, r2 = v;
u = root(u), v = root(v);
if(u == v)
{
if(!cur[u]) cur[u] = w;
return ;
}
if(par[u] > par[v])
{
swap(u, v);
swap(r1, r2);
}
par[u] += par[v];
past[v] = w;
if(par[v] == -1 && !cur[u])
{
if(p1[u] == r1) p1[u] = v;
else if(p2[u] == r1) p2[u] = v;
else cur[u] = w;
}
else if(!cur[u] && !cur[v])
{
if(p1[u] == r1 && p1[v] == r2) p1[u] = p2[v];
else if(p1[u] == r1 && p2[v] == r2) p1[u] = p1[v];
else if(p2[u] == r1 && p1[v] == r2) p2[u] = p2[v];
else if(p2[u] == r1 && p2[v] == r2) p2[u] = p1[v];
else cur[u] = w;
}
else if(!cur[u]) cur[u] = w;
par[v] = u;
}
void init(int n, int m, vector <int> U, vector <int> V, vector <int> W)
{
for(int i = 1; i <= n; i++)
{
p1[i] = p2[i] = i;
par[i] = -1;
}
for(int i = 0; i < m; i++)
{
U[i]++, V[i]++;
edg.push_back({W[i], {U[i], V[i]}});
}
sort(edg.begin(), edg.end());
for(auto [w, e] : edg) join(e.fi, e.se, w);
}
int getMinimumFuelCapacity(int u, int v)
{
u++, v++;
int l = 1, r = edg[edg.size() - 1].fi, mid, ans = -1;
while (l <= r)
{
mid = (l + r) / 2;
if(check(u, v, mid)) ans = mid, r = mid - 1;
else l = mid + 1;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
324 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 |
33 ms |
6324 KB |
Output is correct |
10 |
Correct |
41 ms |
7308 KB |
Output is correct |
11 |
Correct |
42 ms |
7236 KB |
Output is correct |
12 |
Correct |
46 ms |
7604 KB |
Output is correct |
13 |
Correct |
43 ms |
7600 KB |
Output is correct |
14 |
Correct |
48 ms |
6680 KB |
Output is correct |
15 |
Correct |
200 ms |
11468 KB |
Output is correct |
16 |
Correct |
207 ms |
11308 KB |
Output is correct |
17 |
Correct |
205 ms |
11708 KB |
Output is correct |
18 |
Correct |
132 ms |
11792 KB |
Output is correct |
19 |
Correct |
117 ms |
6656 KB |
Output is correct |
20 |
Correct |
192 ms |
12336 KB |
Output is correct |
21 |
Correct |
209 ms |
12720 KB |
Output is correct |
22 |
Correct |
208 ms |
13072 KB |
Output is correct |
23 |
Correct |
133 ms |
13104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
134 ms |
8176 KB |
Output is correct |
4 |
Correct |
134 ms |
8224 KB |
Output is correct |
5 |
Correct |
140 ms |
8488 KB |
Output is correct |
6 |
Correct |
131 ms |
8152 KB |
Output is correct |
7 |
Correct |
143 ms |
8384 KB |
Output is correct |
8 |
Correct |
138 ms |
8112 KB |
Output is correct |
9 |
Correct |
135 ms |
8172 KB |
Output is correct |
10 |
Correct |
136 ms |
8084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
324 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 |
1 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 |
320 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 |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
1 ms |
324 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 |
320 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
324 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 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 |
33 ms |
6324 KB |
Output is correct |
11 |
Correct |
41 ms |
7308 KB |
Output is correct |
12 |
Correct |
42 ms |
7236 KB |
Output is correct |
13 |
Correct |
46 ms |
7604 KB |
Output is correct |
14 |
Correct |
43 ms |
7600 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 |
320 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 |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
324 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 |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
324 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
6 ms |
1428 KB |
Output is correct |
35 |
Correct |
40 ms |
7384 KB |
Output is correct |
36 |
Correct |
40 ms |
7336 KB |
Output is correct |
37 |
Correct |
48 ms |
7612 KB |
Output is correct |
38 |
Correct |
39 ms |
7596 KB |
Output is correct |
39 |
Correct |
40 ms |
7572 KB |
Output is correct |
40 |
Correct |
38 ms |
6976 KB |
Output is correct |
41 |
Correct |
43 ms |
7620 KB |
Output is correct |
42 |
Correct |
39 ms |
7352 KB |
Output is correct |
43 |
Correct |
40 ms |
7360 KB |
Output is correct |
44 |
Correct |
43 ms |
7992 KB |
Output is correct |
45 |
Correct |
63 ms |
10980 KB |
Output is correct |
46 |
Correct |
39 ms |
7348 KB |
Output is correct |
47 |
Correct |
42 ms |
7464 KB |
Output is correct |
48 |
Correct |
44 ms |
8116 KB |
Output is correct |
49 |
Correct |
60 ms |
9956 KB |
Output is correct |
50 |
Correct |
47 ms |
7108 KB |
Output is correct |
51 |
Correct |
55 ms |
8840 KB |
Output is correct |
52 |
Correct |
72 ms |
11912 KB |
Output is correct |
53 |
Correct |
74 ms |
12624 KB |
Output is correct |
54 |
Correct |
85 ms |
13252 KB |
Output is correct |
55 |
Correct |
39 ms |
7340 KB |
Output is correct |
56 |
Correct |
74 ms |
12276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
324 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 |
33 ms |
6324 KB |
Output is correct |
10 |
Correct |
41 ms |
7308 KB |
Output is correct |
11 |
Correct |
42 ms |
7236 KB |
Output is correct |
12 |
Correct |
46 ms |
7604 KB |
Output is correct |
13 |
Correct |
43 ms |
7600 KB |
Output is correct |
14 |
Correct |
48 ms |
6680 KB |
Output is correct |
15 |
Correct |
200 ms |
11468 KB |
Output is correct |
16 |
Correct |
207 ms |
11308 KB |
Output is correct |
17 |
Correct |
205 ms |
11708 KB |
Output is correct |
18 |
Correct |
132 ms |
11792 KB |
Output is correct |
19 |
Correct |
134 ms |
8176 KB |
Output is correct |
20 |
Correct |
134 ms |
8224 KB |
Output is correct |
21 |
Correct |
140 ms |
8488 KB |
Output is correct |
22 |
Correct |
131 ms |
8152 KB |
Output is correct |
23 |
Correct |
143 ms |
8384 KB |
Output is correct |
24 |
Correct |
138 ms |
8112 KB |
Output is correct |
25 |
Correct |
135 ms |
8172 KB |
Output is correct |
26 |
Correct |
136 ms |
8084 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 |
320 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 |
344 KB |
Output is correct |
36 |
Correct |
6 ms |
1428 KB |
Output is correct |
37 |
Correct |
40 ms |
7384 KB |
Output is correct |
38 |
Correct |
40 ms |
7336 KB |
Output is correct |
39 |
Correct |
48 ms |
7612 KB |
Output is correct |
40 |
Correct |
39 ms |
7596 KB |
Output is correct |
41 |
Correct |
40 ms |
7572 KB |
Output is correct |
42 |
Correct |
38 ms |
6976 KB |
Output is correct |
43 |
Correct |
43 ms |
7620 KB |
Output is correct |
44 |
Correct |
39 ms |
7352 KB |
Output is correct |
45 |
Correct |
40 ms |
7360 KB |
Output is correct |
46 |
Correct |
43 ms |
7992 KB |
Output is correct |
47 |
Correct |
22 ms |
1808 KB |
Output is correct |
48 |
Correct |
186 ms |
12212 KB |
Output is correct |
49 |
Correct |
194 ms |
12252 KB |
Output is correct |
50 |
Correct |
185 ms |
12452 KB |
Output is correct |
51 |
Correct |
176 ms |
12444 KB |
Output is correct |
52 |
Correct |
175 ms |
12196 KB |
Output is correct |
53 |
Correct |
206 ms |
11308 KB |
Output is correct |
54 |
Correct |
219 ms |
13060 KB |
Output is correct |
55 |
Correct |
184 ms |
12172 KB |
Output is correct |
56 |
Correct |
128 ms |
12176 KB |
Output is correct |
57 |
Correct |
217 ms |
13496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 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 |
33 ms |
6324 KB |
Output is correct |
11 |
Correct |
41 ms |
7308 KB |
Output is correct |
12 |
Correct |
42 ms |
7236 KB |
Output is correct |
13 |
Correct |
46 ms |
7604 KB |
Output is correct |
14 |
Correct |
43 ms |
7600 KB |
Output is correct |
15 |
Correct |
48 ms |
6680 KB |
Output is correct |
16 |
Correct |
200 ms |
11468 KB |
Output is correct |
17 |
Correct |
207 ms |
11308 KB |
Output is correct |
18 |
Correct |
205 ms |
11708 KB |
Output is correct |
19 |
Correct |
132 ms |
11792 KB |
Output is correct |
20 |
Correct |
134 ms |
8176 KB |
Output is correct |
21 |
Correct |
134 ms |
8224 KB |
Output is correct |
22 |
Correct |
140 ms |
8488 KB |
Output is correct |
23 |
Correct |
131 ms |
8152 KB |
Output is correct |
24 |
Correct |
143 ms |
8384 KB |
Output is correct |
25 |
Correct |
138 ms |
8112 KB |
Output is correct |
26 |
Correct |
135 ms |
8172 KB |
Output is correct |
27 |
Correct |
136 ms |
8084 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 |
320 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 |
344 KB |
Output is correct |
37 |
Correct |
6 ms |
1428 KB |
Output is correct |
38 |
Correct |
40 ms |
7384 KB |
Output is correct |
39 |
Correct |
40 ms |
7336 KB |
Output is correct |
40 |
Correct |
48 ms |
7612 KB |
Output is correct |
41 |
Correct |
39 ms |
7596 KB |
Output is correct |
42 |
Correct |
40 ms |
7572 KB |
Output is correct |
43 |
Correct |
38 ms |
6976 KB |
Output is correct |
44 |
Correct |
43 ms |
7620 KB |
Output is correct |
45 |
Correct |
39 ms |
7352 KB |
Output is correct |
46 |
Correct |
40 ms |
7360 KB |
Output is correct |
47 |
Correct |
43 ms |
7992 KB |
Output is correct |
48 |
Correct |
22 ms |
1808 KB |
Output is correct |
49 |
Correct |
186 ms |
12212 KB |
Output is correct |
50 |
Correct |
194 ms |
12252 KB |
Output is correct |
51 |
Correct |
185 ms |
12452 KB |
Output is correct |
52 |
Correct |
176 ms |
12444 KB |
Output is correct |
53 |
Correct |
175 ms |
12196 KB |
Output is correct |
54 |
Correct |
206 ms |
11308 KB |
Output is correct |
55 |
Correct |
219 ms |
13060 KB |
Output is correct |
56 |
Correct |
184 ms |
12172 KB |
Output is correct |
57 |
Correct |
128 ms |
12176 KB |
Output is correct |
58 |
Correct |
217 ms |
13496 KB |
Output is correct |
59 |
Correct |
117 ms |
6656 KB |
Output is correct |
60 |
Correct |
192 ms |
12336 KB |
Output is correct |
61 |
Correct |
209 ms |
12720 KB |
Output is correct |
62 |
Correct |
208 ms |
13072 KB |
Output is correct |
63 |
Correct |
133 ms |
13104 KB |
Output is correct |
64 |
Correct |
1 ms |
328 KB |
Output is correct |
65 |
Correct |
1 ms |
324 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
320 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
1 ms |
468 KB |
Output is correct |
71 |
Correct |
1 ms |
468 KB |
Output is correct |
72 |
Correct |
1 ms |
324 KB |
Output is correct |
73 |
Correct |
1 ms |
468 KB |
Output is correct |
74 |
Correct |
63 ms |
10980 KB |
Output is correct |
75 |
Correct |
39 ms |
7348 KB |
Output is correct |
76 |
Correct |
42 ms |
7464 KB |
Output is correct |
77 |
Correct |
44 ms |
8116 KB |
Output is correct |
78 |
Correct |
60 ms |
9956 KB |
Output is correct |
79 |
Correct |
47 ms |
7108 KB |
Output is correct |
80 |
Correct |
55 ms |
8840 KB |
Output is correct |
81 |
Correct |
72 ms |
11912 KB |
Output is correct |
82 |
Correct |
74 ms |
12624 KB |
Output is correct |
83 |
Correct |
85 ms |
13252 KB |
Output is correct |
84 |
Correct |
39 ms |
7340 KB |
Output is correct |
85 |
Correct |
74 ms |
12276 KB |
Output is correct |
86 |
Correct |
54 ms |
4772 KB |
Output is correct |
87 |
Correct |
183 ms |
12200 KB |
Output is correct |
88 |
Correct |
185 ms |
12348 KB |
Output is correct |
89 |
Correct |
149 ms |
12596 KB |
Output is correct |
90 |
Correct |
184 ms |
13756 KB |
Output is correct |
91 |
Correct |
188 ms |
13708 KB |
Output is correct |
92 |
Correct |
183 ms |
13724 KB |
Output is correct |
93 |
Correct |
232 ms |
15944 KB |
Output is correct |
94 |
Correct |
216 ms |
16784 KB |
Output is correct |
95 |
Correct |
271 ms |
17128 KB |
Output is correct |
96 |
Correct |
129 ms |
12320 KB |
Output is correct |
97 |
Correct |
197 ms |
14900 KB |
Output is correct |