#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];
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);
root[y] = x;
}
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;
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;
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
89 ms |
3028 KB |
Output is correct |
10 |
Correct |
210 ms |
3668 KB |
Output is correct |
11 |
Correct |
253 ms |
3604 KB |
Output is correct |
12 |
Correct |
268 ms |
3784 KB |
Output is correct |
13 |
Correct |
311 ms |
3784 KB |
Output is correct |
14 |
Execution timed out |
2071 ms |
3172 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Execution timed out |
2045 ms |
5488 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
89 ms |
3028 KB |
Output is correct |
10 |
Correct |
210 ms |
3668 KB |
Output is correct |
11 |
Correct |
253 ms |
3604 KB |
Output is correct |
12 |
Correct |
268 ms |
3784 KB |
Output is correct |
13 |
Correct |
311 ms |
3784 KB |
Output is correct |
14 |
Execution timed out |
2071 ms |
3172 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |