// #include "swap.h"
#include <bits/stdc++.h>
using namespace std;
using tint = array <int, 3>;
const int mxN = 200005;
int n, m, deg[mxN];
tint edge[mxN];
struct dsu {
tint G[mxN]; // node, is cycle, is deg3
void init(){
for (int i = 0; i < n; i++) G[i] = {i, 0, 0};
}
int find(int x){
if (G[x][0] != x) G[x][0] = find(G[x][0]);
return G[x][0];
}
void uni(int x, int y){
x = find(x), y = find(y);
if (x != y){
G[y][0] = x;
G[x][1] += G[y][1];
G[x][2] += G[y][2];
}
else {
G[x][1] = 1;
}
}
} dsu;
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
n = N, m = M;
for (int i = 0; i < m; i++) edge[i] = {W[i], U[i], V[i]};
sort(edge, edge + m);
}
int getMinimumFuelCapacity(int X, int Y) {
dsu.init();
memset(deg, 0, sizeof deg);
for (int i = 0; i < m; i++){
if (++deg[edge[i][1]] >= 3) dsu.G[dsu.find(edge[i][1])][2] = 1;
if (++deg[edge[i][2]] >= 3) dsu.G[dsu.find(edge[i][2])][2] = 1;
dsu.uni(edge[i][1], edge[i][2]);
X = dsu.find(X), Y = dsu.find(Y);
if (X == Y && (dsu.G[X][1] || dsu.G[X][2])){
return edge[i][0];
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
1076 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
27 ms |
4092 KB |
Output is correct |
10 |
Correct |
38 ms |
4740 KB |
Output is correct |
11 |
Correct |
39 ms |
4672 KB |
Output is correct |
12 |
Correct |
42 ms |
4800 KB |
Output is correct |
13 |
Correct |
40 ms |
5048 KB |
Output is correct |
14 |
Execution timed out |
2070 ms |
4272 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Execution timed out |
2045 ms |
6824 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
1076 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
1104 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1084 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1128 KB |
Output is correct |
26 |
Correct |
1 ms |
1092 KB |
Output is correct |
27 |
Correct |
1 ms |
1108 KB |
Output is correct |
28 |
Correct |
1 ms |
1088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1076 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
27 ms |
4092 KB |
Output is correct |
11 |
Correct |
38 ms |
4740 KB |
Output is correct |
12 |
Correct |
39 ms |
4672 KB |
Output is correct |
13 |
Correct |
42 ms |
4800 KB |
Output is correct |
14 |
Correct |
40 ms |
5048 KB |
Output is correct |
15 |
Correct |
1 ms |
1104 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
1 ms |
1084 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
1108 KB |
Output is correct |
27 |
Correct |
1 ms |
1108 KB |
Output is correct |
28 |
Correct |
1 ms |
1108 KB |
Output is correct |
29 |
Correct |
1 ms |
1108 KB |
Output is correct |
30 |
Correct |
1 ms |
1128 KB |
Output is correct |
31 |
Correct |
1 ms |
1092 KB |
Output is correct |
32 |
Correct |
1 ms |
1108 KB |
Output is correct |
33 |
Correct |
1 ms |
1088 KB |
Output is correct |
34 |
Correct |
5 ms |
1952 KB |
Output is correct |
35 |
Correct |
40 ms |
6364 KB |
Output is correct |
36 |
Correct |
40 ms |
6436 KB |
Output is correct |
37 |
Correct |
39 ms |
6432 KB |
Output is correct |
38 |
Correct |
39 ms |
6356 KB |
Output is correct |
39 |
Correct |
40 ms |
6320 KB |
Output is correct |
40 |
Correct |
39 ms |
5892 KB |
Output is correct |
41 |
Correct |
42 ms |
6688 KB |
Output is correct |
42 |
Correct |
41 ms |
6448 KB |
Output is correct |
43 |
Correct |
34 ms |
6440 KB |
Output is correct |
44 |
Correct |
47 ms |
6700 KB |
Output is correct |
45 |
Correct |
61 ms |
8592 KB |
Output is correct |
46 |
Correct |
40 ms |
6368 KB |
Output is correct |
47 |
Correct |
41 ms |
6324 KB |
Output is correct |
48 |
Correct |
47 ms |
6828 KB |
Output is correct |
49 |
Correct |
46 ms |
8564 KB |
Output is correct |
50 |
Correct |
40 ms |
7080 KB |
Output is correct |
51 |
Correct |
49 ms |
7564 KB |
Output is correct |
52 |
Correct |
61 ms |
9424 KB |
Output is correct |
53 |
Correct |
65 ms |
10328 KB |
Output is correct |
54 |
Correct |
72 ms |
11220 KB |
Output is correct |
55 |
Correct |
35 ms |
6440 KB |
Output is correct |
56 |
Correct |
77 ms |
9980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
1076 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
27 ms |
4092 KB |
Output is correct |
10 |
Correct |
38 ms |
4740 KB |
Output is correct |
11 |
Correct |
39 ms |
4672 KB |
Output is correct |
12 |
Correct |
42 ms |
4800 KB |
Output is correct |
13 |
Correct |
40 ms |
5048 KB |
Output is correct |
14 |
Execution timed out |
2070 ms |
4272 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1076 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
27 ms |
4092 KB |
Output is correct |
11 |
Correct |
38 ms |
4740 KB |
Output is correct |
12 |
Correct |
39 ms |
4672 KB |
Output is correct |
13 |
Correct |
42 ms |
4800 KB |
Output is correct |
14 |
Correct |
40 ms |
5048 KB |
Output is correct |
15 |
Execution timed out |
2070 ms |
4272 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |