#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
int i, n, m, ans, curr;
bool visited[100005];
vector<pair<int, int> > adj[100005];
int par[100005];
int dep[100005];
int hd[100005];
pair<int, pair<int, int> > edges[200005];
int find_par(int x) {
if (par[x] == x) return x;
else return par[x] = find_par(par[x]);
}
bool isSame(int x, int y) {
return find_par(x) == find_par(y);
}
void Unite(int x, int y) {
x = find_par(x);
y = find_par(y);
if (x == y) return;
if (dep[x] < dep[y]) swap(x, y);
if (dep[x] == dep[y]) ++dep[x];
par[y] = x;
}
void initDSU() {
for (int i=0; i < n; ++i) {
par[i] = i;
dep[i] = 0;
}
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n = N;
m = M;
for (i=0; i < m; ++i) {
adj[U[i]].push_back(make_pair(V[i], W[i]));
adj[V[i]].push_back(make_pair(U[i], W[i]));
edges[i] = make_pair(W[i], make_pair(U[i], V[i]));
}
sort(edges, edges+m);
}
int f(int a, int b, int c) {
initDSU();
for (int j=0; j < m; ++j) {
if (edges[j].Y.X == c || edges[j].Y.Y == c) continue;
Unite(edges[j].Y.X, edges[j].Y.Y);
if (isSame(a, b)) return edges[j].X;
}
return INT_MAX;
}
int getMinimumFuelCapacity(int fx, int fy) {
ans = INT_MAX;
for (i=0; i < n; ++i) {
if (i == fx || i == fy) continue;
ans = min(ans, max({f(fx, i, fy), f(fy, fx, i), f(i, fy, fx)}));
}
if (ans == INT_MAX) return -1;
else return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
22 ms |
2700 KB |
Output is correct |
5 |
Correct |
85 ms |
2644 KB |
Output is correct |
6 |
Correct |
94 ms |
2716 KB |
Output is correct |
7 |
Correct |
115 ms |
2720 KB |
Output is correct |
8 |
Correct |
99 ms |
2728 KB |
Output is correct |
9 |
Execution timed out |
2080 ms |
7884 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Execution timed out |
2057 ms |
11560 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
22 ms |
2700 KB |
Output is correct |
5 |
Correct |
85 ms |
2644 KB |
Output is correct |
6 |
Correct |
94 ms |
2716 KB |
Output is correct |
7 |
Correct |
115 ms |
2720 KB |
Output is correct |
8 |
Correct |
99 ms |
2728 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
104 ms |
2728 KB |
Output is correct |
11 |
Correct |
138 ms |
2644 KB |
Output is correct |
12 |
Correct |
127 ms |
2720 KB |
Output is correct |
13 |
Correct |
82 ms |
2712 KB |
Output is correct |
14 |
Correct |
89 ms |
2716 KB |
Output is correct |
15 |
Incorrect |
135 ms |
2728 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
22 ms |
2700 KB |
Output is correct |
6 |
Correct |
85 ms |
2644 KB |
Output is correct |
7 |
Correct |
94 ms |
2716 KB |
Output is correct |
8 |
Correct |
115 ms |
2720 KB |
Output is correct |
9 |
Correct |
99 ms |
2728 KB |
Output is correct |
10 |
Execution timed out |
2080 ms |
7884 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
22 ms |
2700 KB |
Output is correct |
5 |
Correct |
85 ms |
2644 KB |
Output is correct |
6 |
Correct |
94 ms |
2716 KB |
Output is correct |
7 |
Correct |
115 ms |
2720 KB |
Output is correct |
8 |
Correct |
99 ms |
2728 KB |
Output is correct |
9 |
Execution timed out |
2080 ms |
7884 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
1 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
22 ms |
2700 KB |
Output is correct |
6 |
Correct |
85 ms |
2644 KB |
Output is correct |
7 |
Correct |
94 ms |
2716 KB |
Output is correct |
8 |
Correct |
115 ms |
2720 KB |
Output is correct |
9 |
Correct |
99 ms |
2728 KB |
Output is correct |
10 |
Execution timed out |
2080 ms |
7884 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |