#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define MAX 100000
#define u second.first
#define v second.second
#define w first
lli n,m,a,b,c,dis,cont;
vector<pair<lli,pair<lli,lli> > > orden;
pair<lli,lli> uf[MAX+2];
lli grado[MAX+2],ciclo[MAX+2];
lli sube(lli act) {
if (uf[act].first == act) return act;
uf[act].first = sube(uf[act].first);
return uf[act].first;
}
void une(lli a, lli b) {
uf[b].first = a;
if (ciclo[b]) ciclo[a] = 1;
}
void init(int N, int M,std::vector<int> U, std::vector<int> V, std::vector<int> W) {
n = N;
m = M;
rep(i,0,m-1) orden.push_back({W[i], {U[i]+1, V[i]+1} });
sort(orden.begin(), orden.end());
}
int getMinimumFuelCapacity(int X, int Y) {
X++;
Y++;
rep(i,1,n) {
uf[i] = {i,0};
grado[i] = 0;
ciclo[i] = 0;
}
for (auto act : orden) {
cont++;
a = sube(act.u);
b = sube(act.v);
grado[act.u]++;
grado[act.v]++;
if (a != b) une(a,b);
else ciclo[a] = 1;
if (grado[act.u] > uf[a].second) uf[a].second = grado[act.u];
if (grado[act.v] > uf[a].second) uf[a].second = grado[act.v];
a = sube(X);
b = sube(Y);
if (a == b) {
if (uf[a].second > 2 || ciclo[a]) return act.w;
}
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
44 ms |
7316 KB |
Output is correct |
10 |
Correct |
60 ms |
8836 KB |
Output is correct |
11 |
Correct |
63 ms |
8752 KB |
Output is correct |
12 |
Correct |
61 ms |
9152 KB |
Output is correct |
13 |
Correct |
58 ms |
9508 KB |
Output is correct |
14 |
Execution timed out |
2070 ms |
7584 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 |
2070 ms |
12560 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 |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
44 ms |
7316 KB |
Output is correct |
11 |
Correct |
60 ms |
8836 KB |
Output is correct |
12 |
Correct |
63 ms |
8752 KB |
Output is correct |
13 |
Correct |
61 ms |
9152 KB |
Output is correct |
14 |
Correct |
58 ms |
9508 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
17 |
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 |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
44 ms |
7316 KB |
Output is correct |
10 |
Correct |
60 ms |
8836 KB |
Output is correct |
11 |
Correct |
63 ms |
8752 KB |
Output is correct |
12 |
Correct |
61 ms |
9152 KB |
Output is correct |
13 |
Correct |
58 ms |
9508 KB |
Output is correct |
14 |
Execution timed out |
2070 ms |
7584 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
44 ms |
7316 KB |
Output is correct |
11 |
Correct |
60 ms |
8836 KB |
Output is correct |
12 |
Correct |
63 ms |
8752 KB |
Output is correct |
13 |
Correct |
61 ms |
9152 KB |
Output is correct |
14 |
Correct |
58 ms |
9508 KB |
Output is correct |
15 |
Execution timed out |
2070 ms |
7584 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |