#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define arr3 array<int, 3>
struct dsu{
vector<int> p, d;
vector<bool> f;
vector<vector<int>> A, out;
int n;
void init(int ns){
n = ns;
d.resize(n + 1);
p.resize(n + 1);
f.resize(n + 1);
A.resize(n + 1);
out.resize(n + 1);
for (int i = 1; i <= n; i++){
out[i].assign(n + 1, -1);
p[i] = i;
A[i] = {i};
}
}
int get(int v){
if (p[v] != v){
p[v] = get(p[v]);
}
return p[v];
}
void unite(int x, int y, int w){
int a = get(x), b = get(y);
if (a == b){
if (!f[a]){
f[a] = 1;
for (int i: A[a]){
for (int j: A[a]){
out[i][j] = w;
}
}
}
return;
}
if (A[a].size() > A[b].size()) swap(a, b);
if (f[a] || f[b] || d[x] >= 2 || d[y] >= 2){
for (int i: A[a]){
for (int j: A[b]){
out[i][j] = out[j][i] = w;
}
}
f[b] = 1;
}
else {
d[x]++; d[y]++;
}
for (int i: A[a]) A[b].pb(i);
p[a] = b;
}
};
dsu T;
void init(int n, int m, vector<int> U, vector<int> V, vector<int> W){
vector<arr3> ed;
for (int i = 0; i < m; i++){
ed.pb({W[i], U[i] + 1, V[i] + 1});
}
sort(ed.begin(), ed.end());
T.init(n);
for (auto [f, x, y]: ed){
T.unite(x, y, f);
}
}
int getMinimumFuelCapacity(int x, int y){
x++; y++;
return T.out[x][y];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
3 ms |
4032 KB |
Output is correct |
6 |
Correct |
4 ms |
3832 KB |
Output is correct |
7 |
Correct |
4 ms |
4432 KB |
Output is correct |
8 |
Correct |
4 ms |
4432 KB |
Output is correct |
9 |
Runtime error |
357 ms |
524288 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Runtime error |
380 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
3 ms |
4032 KB |
Output is correct |
6 |
Correct |
4 ms |
3832 KB |
Output is correct |
7 |
Correct |
4 ms |
4432 KB |
Output is correct |
8 |
Correct |
4 ms |
4432 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
4432 KB |
Output is correct |
11 |
Correct |
5 ms |
4464 KB |
Output is correct |
12 |
Correct |
5 ms |
4344 KB |
Output is correct |
13 |
Correct |
4 ms |
3152 KB |
Output is correct |
14 |
Correct |
4 ms |
3408 KB |
Output is correct |
15 |
Incorrect |
5 ms |
4308 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
3 ms |
4032 KB |
Output is correct |
7 |
Correct |
4 ms |
3832 KB |
Output is correct |
8 |
Correct |
4 ms |
4432 KB |
Output is correct |
9 |
Correct |
4 ms |
4432 KB |
Output is correct |
10 |
Runtime error |
357 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
1116 KB |
Output is correct |
5 |
Correct |
3 ms |
4032 KB |
Output is correct |
6 |
Correct |
4 ms |
3832 KB |
Output is correct |
7 |
Correct |
4 ms |
4432 KB |
Output is correct |
8 |
Correct |
4 ms |
4432 KB |
Output is correct |
9 |
Runtime error |
357 ms |
524288 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
436 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
1116 KB |
Output is correct |
6 |
Correct |
3 ms |
4032 KB |
Output is correct |
7 |
Correct |
4 ms |
3832 KB |
Output is correct |
8 |
Correct |
4 ms |
4432 KB |
Output is correct |
9 |
Correct |
4 ms |
4432 KB |
Output is correct |
10 |
Runtime error |
357 ms |
524288 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |