#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
struct edge{
int u, v, w;
};
int n, m;
const int maxn = 1e5 + 69;
vector <edge> e;
int root[maxn], deg[maxn], edg[maxn];
int find(int x){
if (x == root[x]) return x;
return root[x] = find(root[x]);
}
void unite(int x, int y){
x = find(x); y = find(y);
if (x == y) {
edg[x]++;
return;
}
root[y] = x;
edg[x] += edg[y];
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n = N;
m = M;
e.resize(m);
for (int i = 0; i < m; i++) {
e[i].u = U[i];
e[i].v = V[i];
e[i].w = W[i];
}
}
int getMinimumFuelCapacity(int x, int y) {
int l = 0, r = 1e9 + 1;
while (l != r){
int mid = (l + r)/2;
for (int i = 0; i < n; i++){
root[i] = i;
edg[i] = 0;
deg[i] = 0;
}
for (int i = 0; i < m; i++){
if (e[i].w > mid) continue;
deg[e[i].u]++;
deg[e[i].v]++;
unite(e[i].u, e[i].v);
}
bool found = false;
if (find(x) != find(y)) {
l = mid + 1;
continue;
}
if (edg[find(x)]) {
found = true;
}
for (int i = 0; i < n; i++){
if (find(i) == find(x) && deg[i] >= 3) //can turn here
found = true;
}
if (found) r = mid;
else l = mid + 1;
}
if (l > 1e9) return -1;
return l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
106 ms |
3072 KB |
Output is correct |
10 |
Correct |
251 ms |
3692 KB |
Output is correct |
11 |
Correct |
309 ms |
3636 KB |
Output is correct |
12 |
Correct |
322 ms |
3820 KB |
Output is correct |
13 |
Correct |
396 ms |
3892 KB |
Output is correct |
14 |
Execution timed out |
2078 ms |
3256 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
2082 ms |
5756 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
356 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
3 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
106 ms |
3072 KB |
Output is correct |
11 |
Correct |
251 ms |
3692 KB |
Output is correct |
12 |
Correct |
309 ms |
3636 KB |
Output is correct |
13 |
Correct |
322 ms |
3820 KB |
Output is correct |
14 |
Correct |
396 ms |
3892 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
356 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
3 ms |
340 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
3 ms |
340 KB |
Output is correct |
34 |
Correct |
11 ms |
820 KB |
Output is correct |
35 |
Correct |
365 ms |
3820 KB |
Output is correct |
36 |
Correct |
359 ms |
3812 KB |
Output is correct |
37 |
Correct |
391 ms |
3796 KB |
Output is correct |
38 |
Correct |
352 ms |
3796 KB |
Output is correct |
39 |
Correct |
391 ms |
3772 KB |
Output is correct |
40 |
Correct |
381 ms |
3480 KB |
Output is correct |
41 |
Correct |
400 ms |
3816 KB |
Output is correct |
42 |
Correct |
372 ms |
3820 KB |
Output is correct |
43 |
Correct |
336 ms |
3812 KB |
Output is correct |
44 |
Correct |
423 ms |
3816 KB |
Output is correct |
45 |
Correct |
502 ms |
5452 KB |
Output is correct |
46 |
Correct |
364 ms |
3796 KB |
Output is correct |
47 |
Correct |
399 ms |
3816 KB |
Output is correct |
48 |
Correct |
541 ms |
4168 KB |
Output is correct |
49 |
Correct |
72 ms |
5968 KB |
Output is correct |
50 |
Correct |
98 ms |
4544 KB |
Output is correct |
51 |
Correct |
345 ms |
4752 KB |
Output is correct |
52 |
Correct |
503 ms |
5964 KB |
Output is correct |
53 |
Correct |
485 ms |
6508 KB |
Output is correct |
54 |
Correct |
586 ms |
7268 KB |
Output is correct |
55 |
Correct |
359 ms |
3824 KB |
Output is correct |
56 |
Correct |
718 ms |
6304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
106 ms |
3072 KB |
Output is correct |
10 |
Correct |
251 ms |
3692 KB |
Output is correct |
11 |
Correct |
309 ms |
3636 KB |
Output is correct |
12 |
Correct |
322 ms |
3820 KB |
Output is correct |
13 |
Correct |
396 ms |
3892 KB |
Output is correct |
14 |
Execution timed out |
2078 ms |
3256 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
106 ms |
3072 KB |
Output is correct |
11 |
Correct |
251 ms |
3692 KB |
Output is correct |
12 |
Correct |
309 ms |
3636 KB |
Output is correct |
13 |
Correct |
322 ms |
3820 KB |
Output is correct |
14 |
Correct |
396 ms |
3892 KB |
Output is correct |
15 |
Execution timed out |
2078 ms |
3256 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |