#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;
uf[a].second = max(uf[a].second, uf[b].second);
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 |
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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
37 ms |
5656 KB |
Output is correct |
10 |
Correct |
51 ms |
6748 KB |
Output is correct |
11 |
Correct |
53 ms |
6624 KB |
Output is correct |
12 |
Correct |
56 ms |
7084 KB |
Output is correct |
13 |
Correct |
53 ms |
7284 KB |
Output is correct |
14 |
Execution timed out |
2072 ms |
5780 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 |
Execution timed out |
2084 ms |
8780 KB |
Time limit exceeded |
4 |
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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
10 |
Correct |
37 ms |
5656 KB |
Output is correct |
11 |
Correct |
51 ms |
6748 KB |
Output is correct |
12 |
Correct |
53 ms |
6624 KB |
Output is correct |
13 |
Correct |
56 ms |
7084 KB |
Output is correct |
14 |
Correct |
53 ms |
7284 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
444 KB |
Output is correct |
34 |
Correct |
6 ms |
1744 KB |
Output is correct |
35 |
Correct |
69 ms |
8844 KB |
Output is correct |
36 |
Correct |
58 ms |
8852 KB |
Output is correct |
37 |
Correct |
54 ms |
8852 KB |
Output is correct |
38 |
Correct |
55 ms |
8736 KB |
Output is correct |
39 |
Correct |
57 ms |
8820 KB |
Output is correct |
40 |
Correct |
55 ms |
7924 KB |
Output is correct |
41 |
Correct |
60 ms |
9140 KB |
Output is correct |
42 |
Correct |
56 ms |
8868 KB |
Output is correct |
43 |
Correct |
47 ms |
8836 KB |
Output is correct |
44 |
Correct |
64 ms |
9196 KB |
Output is correct |
45 |
Correct |
80 ms |
13244 KB |
Output is correct |
46 |
Correct |
56 ms |
8868 KB |
Output is correct |
47 |
Correct |
58 ms |
8852 KB |
Output is correct |
48 |
Correct |
62 ms |
9444 KB |
Output is correct |
49 |
Correct |
59 ms |
13008 KB |
Output is correct |
50 |
Correct |
46 ms |
8596 KB |
Output is correct |
51 |
Correct |
63 ms |
9628 KB |
Output is correct |
52 |
Correct |
84 ms |
13756 KB |
Output is correct |
53 |
Correct |
87 ms |
14528 KB |
Output is correct |
54 |
Correct |
97 ms |
15164 KB |
Output is correct |
55 |
Correct |
49 ms |
8836 KB |
Output is correct |
56 |
Correct |
99 ms |
14252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
37 ms |
5656 KB |
Output is correct |
10 |
Correct |
51 ms |
6748 KB |
Output is correct |
11 |
Correct |
53 ms |
6624 KB |
Output is correct |
12 |
Correct |
56 ms |
7084 KB |
Output is correct |
13 |
Correct |
53 ms |
7284 KB |
Output is correct |
14 |
Execution timed out |
2072 ms |
5780 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
10 |
Correct |
37 ms |
5656 KB |
Output is correct |
11 |
Correct |
51 ms |
6748 KB |
Output is correct |
12 |
Correct |
53 ms |
6624 KB |
Output is correct |
13 |
Correct |
56 ms |
7084 KB |
Output is correct |
14 |
Correct |
53 ms |
7284 KB |
Output is correct |
15 |
Execution timed out |
2072 ms |
5780 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |