#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int maxn = 2e5+5;
const int LOG = 20;
int rep[maxn], C[maxn], deg[maxn], dp[maxn], ok[maxn], G[maxn], d[maxn], n, m, N, up[maxn][LOG];
vector<int> adj[maxn];
vector<array<int, 3>> A;
int find(int x){
if(x == rep[x])
return x;
return rep[x] = find(rep[x]); // path compression
}
void merge(int a, int b) {
a = find(a);
b = find(b);
n++;
if(a == b)
C[n] = 1;
rep[n] = rep[a] = rep[b] = n;
if(G[a] or G[b])
G[n] = 1;
if(C[a] or C[b])
C[n] = 1;
adj[n].pb(a);
if(a != b) adj[n].pb(b);
}
void dfs(int x, int pr = -1) {
for(int i = 1; i < LOG; ++i){
if(~up[x][i-1])
up[x][i] = up[up[x][i-1]][i-1];
else
up[x][i] = -1;
}
if(ok[x])
pr = x;
dp[x] = pr;
for(int &i : adj[x]) {
d[i] = d[x]+1;
up[i][0] = x;
// P[i] = x;
dfs(i, pr);
}
}
int LCA(int a, int b) {
if(d[a] < d[b])
swap(a, b);
int diff = d[a]-d[b];
for(int i = LOG-1; i >= 0; --i)
if(diff>>i&1)
a = up[a][i];
if(a == b)
return a;
for(int i = LOG-1; i >= 0; --i)
if(up[a][i] != up[b][i])
a = up[a][i], b = up[b][i];
return up[a][0];
}
void init(int _N, int _M, vector<int> U, vector<int> V, vector<int> W) {
n = _N; N = _N; m = _M;
for(int i = 1; i <= n+m; ++i)
rep[i] = i;
for(int i = 0; i < m; ++i)
A.pb({W[i], U[i]+1, V[i]+1});
sort(all(A));
for(auto &[w, u, v] : A){
deg[u]++, deg[v]++;
if(deg[u] >= 3 or deg[v] >= 3)
G[n+1] = 1;
merge(u, v);
}
for(int i = 1; i <= n; ++i)
ok[i] = (G[i] or C[i]);
dfs(n);
}
int getMinimumFuelCapacity(int x, int y) {
x++, y++;
int ad = LCA(x, y);
if(dp[ad] == -1)
return -1;
return A[dp[ad]-N-1][0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10844 KB |
Output is correct |
3 |
Correct |
1 ms |
10844 KB |
Output is correct |
4 |
Correct |
1 ms |
10844 KB |
Output is correct |
5 |
Correct |
1 ms |
10844 KB |
Output is correct |
6 |
Correct |
1 ms |
10844 KB |
Output is correct |
7 |
Correct |
1 ms |
10844 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
48 ms |
28224 KB |
Output is correct |
10 |
Correct |
54 ms |
31436 KB |
Output is correct |
11 |
Correct |
51 ms |
31172 KB |
Output is correct |
12 |
Correct |
61 ms |
31832 KB |
Output is correct |
13 |
Correct |
63 ms |
35608 KB |
Output is correct |
14 |
Correct |
46 ms |
28364 KB |
Output is correct |
15 |
Correct |
100 ms |
33260 KB |
Output is correct |
16 |
Correct |
92 ms |
33184 KB |
Output is correct |
17 |
Correct |
108 ms |
33620 KB |
Output is correct |
18 |
Correct |
143 ms |
37676 KB |
Output is correct |
19 |
Correct |
43 ms |
16404 KB |
Output is correct |
20 |
Correct |
98 ms |
34376 KB |
Output is correct |
21 |
Correct |
97 ms |
34348 KB |
Output is correct |
22 |
Correct |
99 ms |
34864 KB |
Output is correct |
23 |
Correct |
119 ms |
38896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10844 KB |
Output is correct |
3 |
Correct |
103 ms |
42120 KB |
Output is correct |
4 |
Correct |
102 ms |
42888 KB |
Output is correct |
5 |
Correct |
105 ms |
42588 KB |
Output is correct |
6 |
Correct |
103 ms |
42796 KB |
Output is correct |
7 |
Correct |
103 ms |
42840 KB |
Output is correct |
8 |
Correct |
103 ms |
42076 KB |
Output is correct |
9 |
Correct |
117 ms |
42564 KB |
Output is correct |
10 |
Correct |
102 ms |
41852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10844 KB |
Output is correct |
3 |
Correct |
1 ms |
10844 KB |
Output is correct |
4 |
Correct |
1 ms |
10844 KB |
Output is correct |
5 |
Correct |
1 ms |
10844 KB |
Output is correct |
6 |
Correct |
1 ms |
10844 KB |
Output is correct |
7 |
Correct |
1 ms |
10844 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
1 ms |
10844 KB |
Output is correct |
10 |
Correct |
2 ms |
10908 KB |
Output is correct |
11 |
Correct |
2 ms |
10844 KB |
Output is correct |
12 |
Correct |
1 ms |
10844 KB |
Output is correct |
13 |
Correct |
1 ms |
10844 KB |
Output is correct |
14 |
Correct |
1 ms |
10844 KB |
Output is correct |
15 |
Correct |
2 ms |
10844 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
2 ms |
10844 KB |
Output is correct |
18 |
Correct |
1 ms |
10848 KB |
Output is correct |
19 |
Correct |
1 ms |
10844 KB |
Output is correct |
20 |
Correct |
1 ms |
10852 KB |
Output is correct |
21 |
Correct |
2 ms |
10844 KB |
Output is correct |
22 |
Correct |
2 ms |
11100 KB |
Output is correct |
23 |
Correct |
2 ms |
10844 KB |
Output is correct |
24 |
Correct |
3 ms |
11100 KB |
Output is correct |
25 |
Correct |
2 ms |
11096 KB |
Output is correct |
26 |
Correct |
2 ms |
11096 KB |
Output is correct |
27 |
Correct |
1 ms |
10844 KB |
Output is correct |
28 |
Correct |
2 ms |
11100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10844 KB |
Output is correct |
2 |
Correct |
1 ms |
10840 KB |
Output is correct |
3 |
Correct |
1 ms |
10844 KB |
Output is correct |
4 |
Correct |
1 ms |
10844 KB |
Output is correct |
5 |
Correct |
1 ms |
10844 KB |
Output is correct |
6 |
Correct |
1 ms |
10844 KB |
Output is correct |
7 |
Correct |
1 ms |
10844 KB |
Output is correct |
8 |
Correct |
1 ms |
10844 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
48 ms |
28224 KB |
Output is correct |
11 |
Correct |
54 ms |
31436 KB |
Output is correct |
12 |
Correct |
51 ms |
31172 KB |
Output is correct |
13 |
Correct |
61 ms |
31832 KB |
Output is correct |
14 |
Correct |
63 ms |
35608 KB |
Output is correct |
15 |
Correct |
2 ms |
10908 KB |
Output is correct |
16 |
Correct |
2 ms |
10844 KB |
Output is correct |
17 |
Correct |
1 ms |
10844 KB |
Output is correct |
18 |
Correct |
1 ms |
10844 KB |
Output is correct |
19 |
Correct |
1 ms |
10844 KB |
Output is correct |
20 |
Correct |
2 ms |
10844 KB |
Output is correct |
21 |
Correct |
2 ms |
10844 KB |
Output is correct |
22 |
Correct |
2 ms |
10844 KB |
Output is correct |
23 |
Correct |
1 ms |
10848 KB |
Output is correct |
24 |
Correct |
1 ms |
10844 KB |
Output is correct |
25 |
Correct |
1 ms |
10852 KB |
Output is correct |
26 |
Correct |
2 ms |
10844 KB |
Output is correct |
27 |
Correct |
2 ms |
11100 KB |
Output is correct |
28 |
Correct |
2 ms |
10844 KB |
Output is correct |
29 |
Correct |
3 ms |
11100 KB |
Output is correct |
30 |
Correct |
2 ms |
11096 KB |
Output is correct |
31 |
Correct |
2 ms |
11096 KB |
Output is correct |
32 |
Correct |
1 ms |
10844 KB |
Output is correct |
33 |
Correct |
2 ms |
11100 KB |
Output is correct |
34 |
Correct |
8 ms |
12500 KB |
Output is correct |
35 |
Correct |
59 ms |
31952 KB |
Output is correct |
36 |
Correct |
56 ms |
31944 KB |
Output is correct |
37 |
Correct |
61 ms |
32128 KB |
Output is correct |
38 |
Correct |
56 ms |
31940 KB |
Output is correct |
39 |
Correct |
53 ms |
32120 KB |
Output is correct |
40 |
Correct |
47 ms |
31280 KB |
Output is correct |
41 |
Correct |
56 ms |
31688 KB |
Output is correct |
42 |
Correct |
55 ms |
31896 KB |
Output is correct |
43 |
Correct |
51 ms |
37392 KB |
Output is correct |
44 |
Correct |
57 ms |
32200 KB |
Output is correct |
45 |
Runtime error |
35 ms |
25940 KB |
Execution killed with signal 11 |
46 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10840 KB |
Output is correct |
2 |
Correct |
1 ms |
10844 KB |
Output is correct |
3 |
Correct |
1 ms |
10844 KB |
Output is correct |
4 |
Correct |
1 ms |
10844 KB |
Output is correct |
5 |
Correct |
1 ms |
10844 KB |
Output is correct |
6 |
Correct |
1 ms |
10844 KB |
Output is correct |
7 |
Correct |
1 ms |
10844 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
48 ms |
28224 KB |
Output is correct |
10 |
Correct |
54 ms |
31436 KB |
Output is correct |
11 |
Correct |
51 ms |
31172 KB |
Output is correct |
12 |
Correct |
61 ms |
31832 KB |
Output is correct |
13 |
Correct |
63 ms |
35608 KB |
Output is correct |
14 |
Correct |
46 ms |
28364 KB |
Output is correct |
15 |
Correct |
100 ms |
33260 KB |
Output is correct |
16 |
Correct |
92 ms |
33184 KB |
Output is correct |
17 |
Correct |
108 ms |
33620 KB |
Output is correct |
18 |
Correct |
143 ms |
37676 KB |
Output is correct |
19 |
Correct |
103 ms |
42120 KB |
Output is correct |
20 |
Correct |
102 ms |
42888 KB |
Output is correct |
21 |
Correct |
105 ms |
42588 KB |
Output is correct |
22 |
Correct |
103 ms |
42796 KB |
Output is correct |
23 |
Correct |
103 ms |
42840 KB |
Output is correct |
24 |
Correct |
103 ms |
42076 KB |
Output is correct |
25 |
Correct |
117 ms |
42564 KB |
Output is correct |
26 |
Correct |
102 ms |
41852 KB |
Output is correct |
27 |
Correct |
2 ms |
10908 KB |
Output is correct |
28 |
Correct |
2 ms |
10844 KB |
Output is correct |
29 |
Correct |
1 ms |
10844 KB |
Output is correct |
30 |
Correct |
1 ms |
10844 KB |
Output is correct |
31 |
Correct |
1 ms |
10844 KB |
Output is correct |
32 |
Correct |
2 ms |
10844 KB |
Output is correct |
33 |
Correct |
2 ms |
10844 KB |
Output is correct |
34 |
Correct |
2 ms |
10844 KB |
Output is correct |
35 |
Correct |
1 ms |
10848 KB |
Output is correct |
36 |
Correct |
8 ms |
12500 KB |
Output is correct |
37 |
Correct |
59 ms |
31952 KB |
Output is correct |
38 |
Correct |
56 ms |
31944 KB |
Output is correct |
39 |
Correct |
61 ms |
32128 KB |
Output is correct |
40 |
Correct |
56 ms |
31940 KB |
Output is correct |
41 |
Correct |
53 ms |
32120 KB |
Output is correct |
42 |
Correct |
47 ms |
31280 KB |
Output is correct |
43 |
Correct |
56 ms |
31688 KB |
Output is correct |
44 |
Correct |
55 ms |
31896 KB |
Output is correct |
45 |
Correct |
51 ms |
37392 KB |
Output is correct |
46 |
Correct |
57 ms |
32200 KB |
Output is correct |
47 |
Correct |
13 ms |
12568 KB |
Output is correct |
48 |
Correct |
97 ms |
34324 KB |
Output is correct |
49 |
Correct |
99 ms |
34536 KB |
Output is correct |
50 |
Correct |
100 ms |
34608 KB |
Output is correct |
51 |
Correct |
97 ms |
34616 KB |
Output is correct |
52 |
Correct |
95 ms |
34284 KB |
Output is correct |
53 |
Correct |
85 ms |
29116 KB |
Output is correct |
54 |
Correct |
106 ms |
34900 KB |
Output is correct |
55 |
Correct |
100 ms |
34352 KB |
Output is correct |
56 |
Correct |
118 ms |
38896 KB |
Output is correct |
57 |
Correct |
105 ms |
35372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
10844 KB |
Output is correct |
2 |
Correct |
1 ms |
10840 KB |
Output is correct |
3 |
Correct |
1 ms |
10844 KB |
Output is correct |
4 |
Correct |
1 ms |
10844 KB |
Output is correct |
5 |
Correct |
1 ms |
10844 KB |
Output is correct |
6 |
Correct |
1 ms |
10844 KB |
Output is correct |
7 |
Correct |
1 ms |
10844 KB |
Output is correct |
8 |
Correct |
1 ms |
10844 KB |
Output is correct |
9 |
Correct |
2 ms |
10844 KB |
Output is correct |
10 |
Correct |
48 ms |
28224 KB |
Output is correct |
11 |
Correct |
54 ms |
31436 KB |
Output is correct |
12 |
Correct |
51 ms |
31172 KB |
Output is correct |
13 |
Correct |
61 ms |
31832 KB |
Output is correct |
14 |
Correct |
63 ms |
35608 KB |
Output is correct |
15 |
Correct |
46 ms |
28364 KB |
Output is correct |
16 |
Correct |
100 ms |
33260 KB |
Output is correct |
17 |
Correct |
92 ms |
33184 KB |
Output is correct |
18 |
Correct |
108 ms |
33620 KB |
Output is correct |
19 |
Correct |
143 ms |
37676 KB |
Output is correct |
20 |
Correct |
103 ms |
42120 KB |
Output is correct |
21 |
Correct |
102 ms |
42888 KB |
Output is correct |
22 |
Correct |
105 ms |
42588 KB |
Output is correct |
23 |
Correct |
103 ms |
42796 KB |
Output is correct |
24 |
Correct |
103 ms |
42840 KB |
Output is correct |
25 |
Correct |
103 ms |
42076 KB |
Output is correct |
26 |
Correct |
117 ms |
42564 KB |
Output is correct |
27 |
Correct |
102 ms |
41852 KB |
Output is correct |
28 |
Correct |
2 ms |
10908 KB |
Output is correct |
29 |
Correct |
2 ms |
10844 KB |
Output is correct |
30 |
Correct |
1 ms |
10844 KB |
Output is correct |
31 |
Correct |
1 ms |
10844 KB |
Output is correct |
32 |
Correct |
1 ms |
10844 KB |
Output is correct |
33 |
Correct |
2 ms |
10844 KB |
Output is correct |
34 |
Correct |
2 ms |
10844 KB |
Output is correct |
35 |
Correct |
2 ms |
10844 KB |
Output is correct |
36 |
Correct |
1 ms |
10848 KB |
Output is correct |
37 |
Correct |
8 ms |
12500 KB |
Output is correct |
38 |
Correct |
59 ms |
31952 KB |
Output is correct |
39 |
Correct |
56 ms |
31944 KB |
Output is correct |
40 |
Correct |
61 ms |
32128 KB |
Output is correct |
41 |
Correct |
56 ms |
31940 KB |
Output is correct |
42 |
Correct |
53 ms |
32120 KB |
Output is correct |
43 |
Correct |
47 ms |
31280 KB |
Output is correct |
44 |
Correct |
56 ms |
31688 KB |
Output is correct |
45 |
Correct |
55 ms |
31896 KB |
Output is correct |
46 |
Correct |
51 ms |
37392 KB |
Output is correct |
47 |
Correct |
57 ms |
32200 KB |
Output is correct |
48 |
Correct |
13 ms |
12568 KB |
Output is correct |
49 |
Correct |
97 ms |
34324 KB |
Output is correct |
50 |
Correct |
99 ms |
34536 KB |
Output is correct |
51 |
Correct |
100 ms |
34608 KB |
Output is correct |
52 |
Correct |
97 ms |
34616 KB |
Output is correct |
53 |
Correct |
95 ms |
34284 KB |
Output is correct |
54 |
Correct |
85 ms |
29116 KB |
Output is correct |
55 |
Correct |
106 ms |
34900 KB |
Output is correct |
56 |
Correct |
100 ms |
34352 KB |
Output is correct |
57 |
Correct |
118 ms |
38896 KB |
Output is correct |
58 |
Correct |
105 ms |
35372 KB |
Output is correct |
59 |
Correct |
43 ms |
16404 KB |
Output is correct |
60 |
Correct |
98 ms |
34376 KB |
Output is correct |
61 |
Correct |
97 ms |
34348 KB |
Output is correct |
62 |
Correct |
99 ms |
34864 KB |
Output is correct |
63 |
Correct |
119 ms |
38896 KB |
Output is correct |
64 |
Correct |
1 ms |
10844 KB |
Output is correct |
65 |
Correct |
1 ms |
10852 KB |
Output is correct |
66 |
Correct |
2 ms |
10844 KB |
Output is correct |
67 |
Correct |
2 ms |
11100 KB |
Output is correct |
68 |
Correct |
2 ms |
10844 KB |
Output is correct |
69 |
Correct |
3 ms |
11100 KB |
Output is correct |
70 |
Correct |
2 ms |
11096 KB |
Output is correct |
71 |
Correct |
2 ms |
11096 KB |
Output is correct |
72 |
Correct |
1 ms |
10844 KB |
Output is correct |
73 |
Correct |
2 ms |
11100 KB |
Output is correct |
74 |
Runtime error |
35 ms |
25940 KB |
Execution killed with signal 11 |
75 |
Halted |
0 ms |
0 KB |
- |