#include <bits/stdc++.h>
using namespace std;
const int bigN = 100005;
const int lg = 18;
int tin[bigN], tout[bigN];
int depth[bigN], timer, anc[bigN][lg];
int n, m;
int par[bigN], sz[bigN], cnt[bigN];
bool done[bigN];
vector <tuple <int, int, int> > edges;
/*
bool is_ancestor(int v, int u) {
return (tin[v] <= tin[u] && tout[v] >= tout[u]);
}
int go_up(int v, int u) {
for(int i = lg - 1; i >= 0; i--)
if(!is_ancestor(anc[v][i], u))
v = anc[v][i];
return v;
}
void dfs(int v, int p) {
tin[v] = ++timer;
anc[v][0] = p;
for(int i = 1; i < lg; i++)
anc[v][i] = anc[anc[v][i - 1]][i - 1];
for(auto &u: v) {
if(u == p) continue;
depth[u] = depth[v] + 1;
dfs(u, v);
}
tout[v] = ++timer;
return;
}
int lca(int v, int u) {
if(is_ancestor(v, u)) return v;
if(is_ancestor(u, v)) return u;
return anc[go_up(v, u)][0];
}
*/
int get(int x) {
return ((x == par[x]) ? (x) : (par[x] = get(par[x])));
}
void init(int N, int M, vector <int> V, vector <int> U, vector <int> W) {
n = N; m = M;
for(int i = 0; i < m; i++)
edges.push_back({W[i], V[i], U[i]});
return;
}
void prepare() {
for(int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
cnt[i] = 0;
done[i] = false;
}
return;
}
int getMinimumFuelCapacity(int v, int u) {
prepare();
sort(edges.begin(), edges.end());
for(auto &it: edges) {
int x, y, z;
tie(z, x, y) = it;
cnt[x]++; cnt[y]++;
int X = get(x);
int Y = get(y);
bool flag = (X == Y);
flag |= (cnt[x] >= 3 || cnt[y] >= 3);
if(flag) done[X] = done[Y] = true;
if(sz[X] < sz[Y]) swap(X, Y);
sz[X] += sz[Y];
done[X] |= done[Y];
par[Y] = X;
if(get(v) == get(u) && done[get(v)])
return z;
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
45 ms |
4664 KB |
Output is correct |
10 |
Correct |
65 ms |
5012 KB |
Output is correct |
11 |
Correct |
70 ms |
5052 KB |
Output is correct |
12 |
Correct |
75 ms |
5192 KB |
Output is correct |
13 |
Correct |
69 ms |
5192 KB |
Output is correct |
14 |
Execution timed out |
2078 ms |
4812 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Execution timed out |
2073 ms |
5916 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
320 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
460 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
2 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
45 ms |
4664 KB |
Output is correct |
11 |
Correct |
65 ms |
5012 KB |
Output is correct |
12 |
Correct |
70 ms |
5052 KB |
Output is correct |
13 |
Correct |
75 ms |
5192 KB |
Output is correct |
14 |
Correct |
69 ms |
5192 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
460 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
7 ms |
1296 KB |
Output is correct |
35 |
Correct |
72 ms |
6072 KB |
Output is correct |
36 |
Correct |
76 ms |
6076 KB |
Output is correct |
37 |
Correct |
73 ms |
6072 KB |
Output is correct |
38 |
Correct |
72 ms |
6076 KB |
Output is correct |
39 |
Correct |
75 ms |
6040 KB |
Output is correct |
40 |
Correct |
66 ms |
5692 KB |
Output is correct |
41 |
Correct |
76 ms |
6368 KB |
Output is correct |
42 |
Correct |
90 ms |
6064 KB |
Output is correct |
43 |
Correct |
75 ms |
6076 KB |
Output is correct |
44 |
Correct |
77 ms |
6328 KB |
Output is correct |
45 |
Correct |
105 ms |
10080 KB |
Output is correct |
46 |
Correct |
76 ms |
6072 KB |
Output is correct |
47 |
Correct |
92 ms |
6068 KB |
Output is correct |
48 |
Correct |
78 ms |
6572 KB |
Output is correct |
49 |
Correct |
91 ms |
9952 KB |
Output is correct |
50 |
Correct |
72 ms |
7084 KB |
Output is correct |
51 |
Correct |
85 ms |
7680 KB |
Output is correct |
52 |
Correct |
113 ms |
10620 KB |
Output is correct |
53 |
Correct |
121 ms |
11460 KB |
Output is correct |
54 |
Correct |
132 ms |
12104 KB |
Output is correct |
55 |
Correct |
76 ms |
6076 KB |
Output is correct |
56 |
Correct |
131 ms |
11132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
2 ms |
336 KB |
Output is correct |
9 |
Correct |
45 ms |
4664 KB |
Output is correct |
10 |
Correct |
65 ms |
5012 KB |
Output is correct |
11 |
Correct |
70 ms |
5052 KB |
Output is correct |
12 |
Correct |
75 ms |
5192 KB |
Output is correct |
13 |
Correct |
69 ms |
5192 KB |
Output is correct |
14 |
Execution timed out |
2078 ms |
4812 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
45 ms |
4664 KB |
Output is correct |
11 |
Correct |
65 ms |
5012 KB |
Output is correct |
12 |
Correct |
70 ms |
5052 KB |
Output is correct |
13 |
Correct |
75 ms |
5192 KB |
Output is correct |
14 |
Correct |
69 ms |
5192 KB |
Output is correct |
15 |
Execution timed out |
2078 ms |
4812 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |