#include "swap.h"
#include <vector>
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int MAX_N = 100005;
struct EDGE{
int x,y;
int v;
EDGE(int _x, int _y, int _v): x(_x), y(_y), v(_v){}
};
vector<EDGE> lst;
vector<pair<int, bool> > num[MAX_N];
int par[MAX_N], height[MAX_N];
int deg[MAX_N];
int val[MAX_N];
int m;
int find_par(int x, int max_val){
if(val[x] > max_val){
return x;
}
if(x == par[x]) return x;
return find_par(par[x], max_val);
}
void merge(int x, int y, int v){
deg[x]++;
deg[y]++;
bool Z = false;
if(deg[x] == 3 || deg[y] == 3) Z = true;
x = find_par(x, v);
y = find_par(y, v);
if(x == y){
num[x].push_back(pair<int, bool>(v, true));
return;
}
if(height[y] > height[x]){
swap(x,y);
}
par[y] = x;
val[y] = v;
height[x] += height[x] == height[y];
Z |= num[x].back().se | num[y].back().se;
num[x].push_back(pair<int, bool>(v, Z));
}
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
m = M;
for(int i=0;i<M;i++){
lst.push_back(EDGE(U[i], V[i], W[i]));
}
for(int i=0;i<N;i++){
par[i] = i;
height[i] = 1;
deg[i] = 0;
val[i] = -1;
num[i].push_back(pair<int, bool>(-1, 0));
}
sort(lst.begin(), lst.end(), [&](const EDGE x, const EDGE y){
return x.v < y.v;
});
int i = 0;
for(EDGE p:lst){
merge(p.x, p.y, i);
i++;
}
}
bool is_ok(int max_val, int x, int y){
x = find_par(x, max_val);
y = find_par(y, max_val);
if(x != y) return false;
int idx = lower_bound(num[x].begin(), num[x].end(), pair<int, bool>(max_val + 1, false)) - num[x].begin() - 1;
return num[x][idx].se;
}
int getMinimumFuelCapacity(int X, int Y) {
int l = 0, r = m-1;
while(l < r){
int mid = (l + r) >> 1;
if(is_ok(mid, X, Y)){
r = mid;
}else{
l = mid + 1;
}
}
return is_ok(l, X, Y) ? lst[l].v : -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
3 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
69 ms |
10348 KB |
Output is correct |
10 |
Correct |
87 ms |
12016 KB |
Output is correct |
11 |
Correct |
88 ms |
11760 KB |
Output is correct |
12 |
Correct |
96 ms |
12396 KB |
Output is correct |
13 |
Correct |
77 ms |
12524 KB |
Output is correct |
14 |
Correct |
88 ms |
10348 KB |
Output is correct |
15 |
Correct |
277 ms |
13944 KB |
Output is correct |
16 |
Correct |
276 ms |
13752 KB |
Output is correct |
17 |
Correct |
289 ms |
14164 KB |
Output is correct |
18 |
Correct |
252 ms |
13904 KB |
Output is correct |
19 |
Correct |
146 ms |
7736 KB |
Output is correct |
20 |
Correct |
295 ms |
15048 KB |
Output is correct |
21 |
Correct |
290 ms |
15012 KB |
Output is correct |
22 |
Correct |
301 ms |
15568 KB |
Output is correct |
23 |
Correct |
254 ms |
15316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
323 ms |
14484 KB |
Output is correct |
4 |
Correct |
319 ms |
14932 KB |
Output is correct |
5 |
Correct |
340 ms |
14852 KB |
Output is correct |
6 |
Correct |
310 ms |
14804 KB |
Output is correct |
7 |
Correct |
334 ms |
14920 KB |
Output is correct |
8 |
Correct |
327 ms |
14492 KB |
Output is correct |
9 |
Correct |
325 ms |
14692 KB |
Output is correct |
10 |
Correct |
324 ms |
14472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
3 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
3 ms |
2816 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
3 ms |
2816 KB |
Output is correct |
12 |
Correct |
3 ms |
2816 KB |
Output is correct |
13 |
Correct |
3 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2816 KB |
Output is correct |
16 |
Correct |
3 ms |
2816 KB |
Output is correct |
17 |
Correct |
3 ms |
2816 KB |
Output is correct |
18 |
Correct |
3 ms |
2816 KB |
Output is correct |
19 |
Correct |
3 ms |
2816 KB |
Output is correct |
20 |
Correct |
3 ms |
2816 KB |
Output is correct |
21 |
Correct |
3 ms |
2816 KB |
Output is correct |
22 |
Correct |
3 ms |
2816 KB |
Output is correct |
23 |
Correct |
3 ms |
2816 KB |
Output is correct |
24 |
Correct |
3 ms |
2816 KB |
Output is correct |
25 |
Correct |
3 ms |
2816 KB |
Output is correct |
26 |
Correct |
3 ms |
2816 KB |
Output is correct |
27 |
Correct |
3 ms |
2816 KB |
Output is correct |
28 |
Correct |
3 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
3 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
3 ms |
2816 KB |
Output is correct |
10 |
Correct |
69 ms |
10348 KB |
Output is correct |
11 |
Correct |
87 ms |
12016 KB |
Output is correct |
12 |
Correct |
88 ms |
11760 KB |
Output is correct |
13 |
Correct |
96 ms |
12396 KB |
Output is correct |
14 |
Correct |
77 ms |
12524 KB |
Output is correct |
15 |
Correct |
2 ms |
2816 KB |
Output is correct |
16 |
Correct |
3 ms |
2816 KB |
Output is correct |
17 |
Correct |
3 ms |
2816 KB |
Output is correct |
18 |
Correct |
3 ms |
2688 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 KB |
Output is correct |
20 |
Correct |
3 ms |
2816 KB |
Output is correct |
21 |
Correct |
3 ms |
2816 KB |
Output is correct |
22 |
Correct |
3 ms |
2816 KB |
Output is correct |
23 |
Correct |
3 ms |
2816 KB |
Output is correct |
24 |
Correct |
12 ms |
4032 KB |
Output is correct |
25 |
Correct |
92 ms |
12268 KB |
Output is correct |
26 |
Correct |
99 ms |
12396 KB |
Output is correct |
27 |
Correct |
92 ms |
12268 KB |
Output is correct |
28 |
Correct |
86 ms |
12268 KB |
Output is correct |
29 |
Correct |
89 ms |
12144 KB |
Output is correct |
30 |
Correct |
81 ms |
11244 KB |
Output is correct |
31 |
Correct |
99 ms |
12400 KB |
Output is correct |
32 |
Correct |
92 ms |
12396 KB |
Output is correct |
33 |
Correct |
76 ms |
12396 KB |
Output is correct |
34 |
Correct |
91 ms |
12268 KB |
Output is correct |
35 |
Correct |
3 ms |
2816 KB |
Output is correct |
36 |
Correct |
3 ms |
2816 KB |
Output is correct |
37 |
Correct |
3 ms |
2816 KB |
Output is correct |
38 |
Correct |
3 ms |
2816 KB |
Output is correct |
39 |
Correct |
3 ms |
2816 KB |
Output is correct |
40 |
Correct |
3 ms |
2816 KB |
Output is correct |
41 |
Correct |
3 ms |
2816 KB |
Output is correct |
42 |
Correct |
3 ms |
2816 KB |
Output is correct |
43 |
Correct |
3 ms |
2816 KB |
Output is correct |
44 |
Correct |
3 ms |
2816 KB |
Output is correct |
45 |
Correct |
110 ms |
13928 KB |
Output is correct |
46 |
Correct |
90 ms |
12268 KB |
Output is correct |
47 |
Correct |
90 ms |
12268 KB |
Output is correct |
48 |
Correct |
90 ms |
12720 KB |
Output is correct |
49 |
Correct |
96 ms |
11624 KB |
Output is correct |
50 |
Correct |
72 ms |
9324 KB |
Output is correct |
51 |
Correct |
93 ms |
12396 KB |
Output is correct |
52 |
Correct |
139 ms |
15592 KB |
Output is correct |
53 |
Correct |
152 ms |
16232 KB |
Output is correct |
54 |
Correct |
160 ms |
17636 KB |
Output is correct |
55 |
Correct |
74 ms |
12268 KB |
Output is correct |
56 |
Correct |
137 ms |
15996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
3 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
69 ms |
10348 KB |
Output is correct |
10 |
Correct |
87 ms |
12016 KB |
Output is correct |
11 |
Correct |
88 ms |
11760 KB |
Output is correct |
12 |
Correct |
96 ms |
12396 KB |
Output is correct |
13 |
Correct |
77 ms |
12524 KB |
Output is correct |
14 |
Correct |
88 ms |
10348 KB |
Output is correct |
15 |
Correct |
277 ms |
13944 KB |
Output is correct |
16 |
Correct |
276 ms |
13752 KB |
Output is correct |
17 |
Correct |
289 ms |
14164 KB |
Output is correct |
18 |
Correct |
252 ms |
13904 KB |
Output is correct |
19 |
Correct |
323 ms |
14484 KB |
Output is correct |
20 |
Correct |
319 ms |
14932 KB |
Output is correct |
21 |
Correct |
340 ms |
14852 KB |
Output is correct |
22 |
Correct |
310 ms |
14804 KB |
Output is correct |
23 |
Correct |
334 ms |
14920 KB |
Output is correct |
24 |
Correct |
327 ms |
14492 KB |
Output is correct |
25 |
Correct |
325 ms |
14692 KB |
Output is correct |
26 |
Correct |
324 ms |
14472 KB |
Output is correct |
27 |
Correct |
2 ms |
2816 KB |
Output is correct |
28 |
Correct |
3 ms |
2816 KB |
Output is correct |
29 |
Correct |
3 ms |
2816 KB |
Output is correct |
30 |
Correct |
3 ms |
2688 KB |
Output is correct |
31 |
Correct |
2 ms |
2688 KB |
Output is correct |
32 |
Correct |
3 ms |
2816 KB |
Output is correct |
33 |
Correct |
3 ms |
2816 KB |
Output is correct |
34 |
Correct |
3 ms |
2816 KB |
Output is correct |
35 |
Correct |
3 ms |
2816 KB |
Output is correct |
36 |
Correct |
12 ms |
4032 KB |
Output is correct |
37 |
Correct |
92 ms |
12268 KB |
Output is correct |
38 |
Correct |
99 ms |
12396 KB |
Output is correct |
39 |
Correct |
92 ms |
12268 KB |
Output is correct |
40 |
Correct |
86 ms |
12268 KB |
Output is correct |
41 |
Correct |
89 ms |
12144 KB |
Output is correct |
42 |
Correct |
81 ms |
11244 KB |
Output is correct |
43 |
Correct |
99 ms |
12400 KB |
Output is correct |
44 |
Correct |
92 ms |
12396 KB |
Output is correct |
45 |
Correct |
76 ms |
12396 KB |
Output is correct |
46 |
Correct |
91 ms |
12268 KB |
Output is correct |
47 |
Correct |
30 ms |
4280 KB |
Output is correct |
48 |
Correct |
299 ms |
14928 KB |
Output is correct |
49 |
Correct |
298 ms |
15128 KB |
Output is correct |
50 |
Correct |
301 ms |
14932 KB |
Output is correct |
51 |
Correct |
308 ms |
14816 KB |
Output is correct |
52 |
Correct |
307 ms |
14364 KB |
Output is correct |
53 |
Correct |
284 ms |
12604 KB |
Output is correct |
54 |
Correct |
313 ms |
15572 KB |
Output is correct |
55 |
Correct |
290 ms |
14996 KB |
Output is correct |
56 |
Correct |
282 ms |
14800 KB |
Output is correct |
57 |
Correct |
347 ms |
15572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
2 ms |
2688 KB |
Output is correct |
6 |
Correct |
3 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
3 ms |
2816 KB |
Output is correct |
10 |
Correct |
69 ms |
10348 KB |
Output is correct |
11 |
Correct |
87 ms |
12016 KB |
Output is correct |
12 |
Correct |
88 ms |
11760 KB |
Output is correct |
13 |
Correct |
96 ms |
12396 KB |
Output is correct |
14 |
Correct |
77 ms |
12524 KB |
Output is correct |
15 |
Correct |
88 ms |
10348 KB |
Output is correct |
16 |
Correct |
277 ms |
13944 KB |
Output is correct |
17 |
Correct |
276 ms |
13752 KB |
Output is correct |
18 |
Correct |
289 ms |
14164 KB |
Output is correct |
19 |
Correct |
252 ms |
13904 KB |
Output is correct |
20 |
Correct |
323 ms |
14484 KB |
Output is correct |
21 |
Correct |
319 ms |
14932 KB |
Output is correct |
22 |
Correct |
340 ms |
14852 KB |
Output is correct |
23 |
Correct |
310 ms |
14804 KB |
Output is correct |
24 |
Correct |
334 ms |
14920 KB |
Output is correct |
25 |
Correct |
327 ms |
14492 KB |
Output is correct |
26 |
Correct |
325 ms |
14692 KB |
Output is correct |
27 |
Correct |
324 ms |
14472 KB |
Output is correct |
28 |
Correct |
2 ms |
2816 KB |
Output is correct |
29 |
Correct |
3 ms |
2816 KB |
Output is correct |
30 |
Correct |
3 ms |
2816 KB |
Output is correct |
31 |
Correct |
3 ms |
2688 KB |
Output is correct |
32 |
Correct |
2 ms |
2688 KB |
Output is correct |
33 |
Correct |
3 ms |
2816 KB |
Output is correct |
34 |
Correct |
3 ms |
2816 KB |
Output is correct |
35 |
Correct |
3 ms |
2816 KB |
Output is correct |
36 |
Correct |
3 ms |
2816 KB |
Output is correct |
37 |
Correct |
12 ms |
4032 KB |
Output is correct |
38 |
Correct |
92 ms |
12268 KB |
Output is correct |
39 |
Correct |
99 ms |
12396 KB |
Output is correct |
40 |
Correct |
92 ms |
12268 KB |
Output is correct |
41 |
Correct |
86 ms |
12268 KB |
Output is correct |
42 |
Correct |
89 ms |
12144 KB |
Output is correct |
43 |
Correct |
81 ms |
11244 KB |
Output is correct |
44 |
Correct |
99 ms |
12400 KB |
Output is correct |
45 |
Correct |
92 ms |
12396 KB |
Output is correct |
46 |
Correct |
76 ms |
12396 KB |
Output is correct |
47 |
Correct |
91 ms |
12268 KB |
Output is correct |
48 |
Correct |
30 ms |
4280 KB |
Output is correct |
49 |
Correct |
299 ms |
14928 KB |
Output is correct |
50 |
Correct |
298 ms |
15128 KB |
Output is correct |
51 |
Correct |
301 ms |
14932 KB |
Output is correct |
52 |
Correct |
308 ms |
14816 KB |
Output is correct |
53 |
Correct |
307 ms |
14364 KB |
Output is correct |
54 |
Correct |
284 ms |
12604 KB |
Output is correct |
55 |
Correct |
313 ms |
15572 KB |
Output is correct |
56 |
Correct |
290 ms |
14996 KB |
Output is correct |
57 |
Correct |
282 ms |
14800 KB |
Output is correct |
58 |
Correct |
347 ms |
15572 KB |
Output is correct |
59 |
Correct |
146 ms |
7736 KB |
Output is correct |
60 |
Correct |
295 ms |
15048 KB |
Output is correct |
61 |
Correct |
290 ms |
15012 KB |
Output is correct |
62 |
Correct |
301 ms |
15568 KB |
Output is correct |
63 |
Correct |
254 ms |
15316 KB |
Output is correct |
64 |
Correct |
3 ms |
2816 KB |
Output is correct |
65 |
Correct |
3 ms |
2816 KB |
Output is correct |
66 |
Correct |
3 ms |
2816 KB |
Output is correct |
67 |
Correct |
3 ms |
2816 KB |
Output is correct |
68 |
Correct |
3 ms |
2816 KB |
Output is correct |
69 |
Correct |
3 ms |
2816 KB |
Output is correct |
70 |
Correct |
3 ms |
2816 KB |
Output is correct |
71 |
Correct |
3 ms |
2816 KB |
Output is correct |
72 |
Correct |
3 ms |
2816 KB |
Output is correct |
73 |
Correct |
3 ms |
2816 KB |
Output is correct |
74 |
Correct |
110 ms |
13928 KB |
Output is correct |
75 |
Correct |
90 ms |
12268 KB |
Output is correct |
76 |
Correct |
90 ms |
12268 KB |
Output is correct |
77 |
Correct |
90 ms |
12720 KB |
Output is correct |
78 |
Correct |
96 ms |
11624 KB |
Output is correct |
79 |
Correct |
72 ms |
9324 KB |
Output is correct |
80 |
Correct |
93 ms |
12396 KB |
Output is correct |
81 |
Correct |
139 ms |
15592 KB |
Output is correct |
82 |
Correct |
152 ms |
16232 KB |
Output is correct |
83 |
Correct |
160 ms |
17636 KB |
Output is correct |
84 |
Correct |
74 ms |
12268 KB |
Output is correct |
85 |
Correct |
137 ms |
15996 KB |
Output is correct |
86 |
Correct |
117 ms |
7076 KB |
Output is correct |
87 |
Correct |
326 ms |
14932 KB |
Output is correct |
88 |
Correct |
304 ms |
14912 KB |
Output is correct |
89 |
Correct |
405 ms |
14988 KB |
Output is correct |
90 |
Correct |
380 ms |
13544 KB |
Output is correct |
91 |
Correct |
401 ms |
13484 KB |
Output is correct |
92 |
Correct |
424 ms |
14284 KB |
Output is correct |
93 |
Correct |
481 ms |
17952 KB |
Output is correct |
94 |
Correct |
479 ms |
18628 KB |
Output is correct |
95 |
Correct |
383 ms |
19432 KB |
Output is correct |
96 |
Correct |
284 ms |
14932 KB |
Output is correct |
97 |
Correct |
453 ms |
16936 KB |
Output is correct |