#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;
return (x == par[x]) ? (x) : (par[x] = 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 |
2 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 |
2 ms |
2816 KB |
Output is correct |
9 |
Correct |
75 ms |
10220 KB |
Output is correct |
10 |
Correct |
95 ms |
12012 KB |
Output is correct |
11 |
Correct |
91 ms |
11880 KB |
Output is correct |
12 |
Correct |
101 ms |
12340 KB |
Output is correct |
13 |
Correct |
90 ms |
12524 KB |
Output is correct |
14 |
Correct |
90 ms |
10348 KB |
Output is correct |
15 |
Correct |
257 ms |
13816 KB |
Output is correct |
16 |
Correct |
253 ms |
13756 KB |
Output is correct |
17 |
Correct |
262 ms |
14164 KB |
Output is correct |
18 |
Correct |
311 ms |
13904 KB |
Output is correct |
19 |
Correct |
128 ms |
7736 KB |
Output is correct |
20 |
Correct |
247 ms |
15208 KB |
Output is correct |
21 |
Correct |
246 ms |
15016 KB |
Output is correct |
22 |
Correct |
261 ms |
15572 KB |
Output is correct |
23 |
Correct |
318 ms |
15412 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 |
355 ms |
14492 KB |
Output is correct |
4 |
Correct |
343 ms |
14804 KB |
Output is correct |
5 |
Correct |
362 ms |
14848 KB |
Output is correct |
6 |
Correct |
337 ms |
14804 KB |
Output is correct |
7 |
Correct |
360 ms |
14956 KB |
Output is correct |
8 |
Correct |
352 ms |
14492 KB |
Output is correct |
9 |
Correct |
350 ms |
14700 KB |
Output is correct |
10 |
Correct |
350 ms |
14508 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 |
2 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 |
2 ms |
2816 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
2 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 |
2 ms |
2816 KB |
Output is correct |
10 |
Correct |
75 ms |
10220 KB |
Output is correct |
11 |
Correct |
95 ms |
12012 KB |
Output is correct |
12 |
Correct |
91 ms |
11880 KB |
Output is correct |
13 |
Correct |
101 ms |
12340 KB |
Output is correct |
14 |
Correct |
90 ms |
12524 KB |
Output is correct |
15 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
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 |
2 ms |
2816 KB |
Output is correct |
9 |
Correct |
75 ms |
10220 KB |
Output is correct |
10 |
Correct |
95 ms |
12012 KB |
Output is correct |
11 |
Correct |
91 ms |
11880 KB |
Output is correct |
12 |
Correct |
101 ms |
12340 KB |
Output is correct |
13 |
Correct |
90 ms |
12524 KB |
Output is correct |
14 |
Correct |
90 ms |
10348 KB |
Output is correct |
15 |
Correct |
257 ms |
13816 KB |
Output is correct |
16 |
Correct |
253 ms |
13756 KB |
Output is correct |
17 |
Correct |
262 ms |
14164 KB |
Output is correct |
18 |
Correct |
311 ms |
13904 KB |
Output is correct |
19 |
Correct |
355 ms |
14492 KB |
Output is correct |
20 |
Correct |
343 ms |
14804 KB |
Output is correct |
21 |
Correct |
362 ms |
14848 KB |
Output is correct |
22 |
Correct |
337 ms |
14804 KB |
Output is correct |
23 |
Correct |
360 ms |
14956 KB |
Output is correct |
24 |
Correct |
352 ms |
14492 KB |
Output is correct |
25 |
Correct |
350 ms |
14700 KB |
Output is correct |
26 |
Correct |
350 ms |
14508 KB |
Output is correct |
27 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
2 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 |
2 ms |
2816 KB |
Output is correct |
10 |
Correct |
75 ms |
10220 KB |
Output is correct |
11 |
Correct |
95 ms |
12012 KB |
Output is correct |
12 |
Correct |
91 ms |
11880 KB |
Output is correct |
13 |
Correct |
101 ms |
12340 KB |
Output is correct |
14 |
Correct |
90 ms |
12524 KB |
Output is correct |
15 |
Correct |
90 ms |
10348 KB |
Output is correct |
16 |
Correct |
257 ms |
13816 KB |
Output is correct |
17 |
Correct |
253 ms |
13756 KB |
Output is correct |
18 |
Correct |
262 ms |
14164 KB |
Output is correct |
19 |
Correct |
311 ms |
13904 KB |
Output is correct |
20 |
Correct |
355 ms |
14492 KB |
Output is correct |
21 |
Correct |
343 ms |
14804 KB |
Output is correct |
22 |
Correct |
362 ms |
14848 KB |
Output is correct |
23 |
Correct |
337 ms |
14804 KB |
Output is correct |
24 |
Correct |
360 ms |
14956 KB |
Output is correct |
25 |
Correct |
352 ms |
14492 KB |
Output is correct |
26 |
Correct |
350 ms |
14700 KB |
Output is correct |
27 |
Correct |
350 ms |
14508 KB |
Output is correct |
28 |
Incorrect |
2 ms |
2816 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |