#include "swap.h"
#include <bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << endl, exit(0);
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = (int)1e6 + 7;
const int LG = 18;
const int MOD = 998244353;
const int INF = (int)1e18 + 7;
int n, m, t, flag, k, u, v, w, ans, ans2, tmp, tmp2, tmp3, tmp4, q, timer;
int arr[MAXN], num[MAXN];
int par[MAXN], love[MAXN], dp[MAXN], deg[MAXN];
int h[MAXN], dad[MAXN], pow2dad[MAXN][LG];
vector<pair<int, pii> > edge;
vector<int> adj[MAXN];
/* DSU */
inline int get_par(int v) {
return (par[v] == v? v : par[v] = get_par(par[v]));
}
void unite(int u, int v, int w) {
int u2, v2;
u2 = u;
v2 = v;
deg[u2]++, deg[v2]++;
u = get_par(u), v = get_par(v);
if (u == v) {
if (!love[u]) {
love[u] = 1;
num[u] = w;
}
} else {
par[u] = par[v] = flag;
par[flag] = flag;
adj[flag].pb(u), adj[flag].pb(v);
num[flag] = w;
if (love[u] || love[v]) {
love[flag] = 1;
} else {
love[flag] = (deg[u2] == 3 || deg[v2] == 3);
}
// cout << "@" << flag << " " << u << " " << v << endl;
flag++;
}
}
/* DSU */
/* LCA */
inline int up(int v, int k) {
for (int i=LG-1; i>=0; i--) {
if ((1<<i) <= k) {
k -= (1<<i);
v = pow2dad[v][i];
}
}
return v;
}
int LCA(int u, int v) {
if (h[u] < h[v]) swap(u, v);
u = up(u, h[u]-h[v]);
for (int i=LG-1; i>=0; i--) {
if (h[v] >= (1<<i) && pow2dad[v][i] != pow2dad[u][i]) {
v = pow2dad[v][i];
u = pow2dad[u][i];
}
}
if (u == v) return u;
return dad[v];
}
/* LCA */
// void DFS(int v) {
// for (int u:adj[v]) {
// if (u != dad[v]) {
// dad[u] = v;
// h[u] = h[v]+1;
// DFS(u);
// love[v] |= love[u];
// }
// }
// dp[v] = (love[v]? v : dp[dad[v]]);
// }
void DFS(int v) {
dp[v] = (love[v]? v : dp[dad[v]]);
for (int u:adj[v]) {
if (u != dad[v]) {
dad[u] = v;
h[u] = h[v]+1;
DFS(u);
}
}
}
void DFS2(int v) {
dp[v] = (love[v]? v : dp[dad[v]]);
for (int u:adj[v]) if (u != dad[v]) DFS2(u);
}
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++) {
// cin >> u >> v >> w;
u = U[i];
v = V[i];
w = W[i];
edge.pb(mp(w, mp(u, v)));
}
sort(all(edge));
flag = n+1;
for (int i=1; i<=n; i++) par[i] = i;
for (int i=0; i<m; i++) unite(edge[i].S.F, edge[i].S.S, edge[i].F);
flag--;
DFS(flag);
// DFS2(flag);
for (int i=1; i<=flag; i++) pow2dad[i][0] = dad[i];
for (int j=1; j<LG; j++) for (int i=1; i<=flag; i++) pow2dad[i][j] = pow2dad[pow2dad[i][j-1]][j-1];
num[0]--;
}
int getMinimumFuelCapacity(int X, int Y) {
return num[dp[LCA(X, Y)]];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31324 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
7 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31324 KB |
Output is correct |
5 |
Correct |
7 ms |
31356 KB |
Output is correct |
6 |
Correct |
7 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31324 KB |
Output is correct |
9 |
Correct |
51 ms |
50372 KB |
Output is correct |
10 |
Correct |
72 ms |
55936 KB |
Output is correct |
11 |
Correct |
61 ms |
55772 KB |
Output is correct |
12 |
Correct |
64 ms |
58568 KB |
Output is correct |
13 |
Correct |
60 ms |
61704 KB |
Output is correct |
14 |
Correct |
56 ms |
50888 KB |
Output is correct |
15 |
Correct |
121 ms |
61628 KB |
Output is correct |
16 |
Correct |
123 ms |
59236 KB |
Output is correct |
17 |
Correct |
126 ms |
62084 KB |
Output is correct |
18 |
Correct |
161 ms |
65124 KB |
Output is correct |
19 |
Correct |
67 ms |
41908 KB |
Output is correct |
20 |
Correct |
123 ms |
64128 KB |
Output is correct |
21 |
Correct |
119 ms |
61824 KB |
Output is correct |
22 |
Correct |
128 ms |
64876 KB |
Output is correct |
23 |
Correct |
168 ms |
67884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31324 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Incorrect |
143 ms |
67220 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31324 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
7 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31324 KB |
Output is correct |
5 |
Correct |
7 ms |
31356 KB |
Output is correct |
6 |
Correct |
7 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31324 KB |
Output is correct |
9 |
Correct |
8 ms |
33372 KB |
Output is correct |
10 |
Correct |
7 ms |
33372 KB |
Output is correct |
11 |
Correct |
7 ms |
33372 KB |
Output is correct |
12 |
Correct |
7 ms |
33372 KB |
Output is correct |
13 |
Correct |
7 ms |
33372 KB |
Output is correct |
14 |
Correct |
7 ms |
33372 KB |
Output is correct |
15 |
Correct |
8 ms |
33372 KB |
Output is correct |
16 |
Correct |
7 ms |
33440 KB |
Output is correct |
17 |
Correct |
8 ms |
33488 KB |
Output is correct |
18 |
Correct |
7 ms |
33372 KB |
Output is correct |
19 |
Correct |
7 ms |
33372 KB |
Output is correct |
20 |
Correct |
8 ms |
33372 KB |
Output is correct |
21 |
Correct |
7 ms |
33372 KB |
Output is correct |
22 |
Correct |
7 ms |
33372 KB |
Output is correct |
23 |
Correct |
7 ms |
33372 KB |
Output is correct |
24 |
Correct |
8 ms |
33372 KB |
Output is correct |
25 |
Correct |
7 ms |
33480 KB |
Output is correct |
26 |
Correct |
7 ms |
33412 KB |
Output is correct |
27 |
Correct |
8 ms |
33372 KB |
Output is correct |
28 |
Correct |
8 ms |
33628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
33372 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31324 KB |
Output is correct |
5 |
Correct |
7 ms |
31324 KB |
Output is correct |
6 |
Correct |
7 ms |
31356 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31324 KB |
Output is correct |
9 |
Correct |
7 ms |
31324 KB |
Output is correct |
10 |
Correct |
51 ms |
50372 KB |
Output is correct |
11 |
Correct |
72 ms |
55936 KB |
Output is correct |
12 |
Correct |
61 ms |
55772 KB |
Output is correct |
13 |
Correct |
64 ms |
58568 KB |
Output is correct |
14 |
Correct |
60 ms |
61704 KB |
Output is correct |
15 |
Correct |
7 ms |
33372 KB |
Output is correct |
16 |
Correct |
7 ms |
33372 KB |
Output is correct |
17 |
Correct |
7 ms |
33372 KB |
Output is correct |
18 |
Correct |
7 ms |
33372 KB |
Output is correct |
19 |
Correct |
7 ms |
33372 KB |
Output is correct |
20 |
Correct |
8 ms |
33372 KB |
Output is correct |
21 |
Correct |
7 ms |
33440 KB |
Output is correct |
22 |
Correct |
8 ms |
33488 KB |
Output is correct |
23 |
Correct |
7 ms |
33372 KB |
Output is correct |
24 |
Correct |
7 ms |
33372 KB |
Output is correct |
25 |
Correct |
8 ms |
33372 KB |
Output is correct |
26 |
Correct |
7 ms |
33372 KB |
Output is correct |
27 |
Correct |
7 ms |
33372 KB |
Output is correct |
28 |
Correct |
7 ms |
33372 KB |
Output is correct |
29 |
Correct |
8 ms |
33372 KB |
Output is correct |
30 |
Correct |
7 ms |
33480 KB |
Output is correct |
31 |
Correct |
7 ms |
33412 KB |
Output is correct |
32 |
Correct |
8 ms |
33372 KB |
Output is correct |
33 |
Correct |
8 ms |
33628 KB |
Output is correct |
34 |
Correct |
14 ms |
36964 KB |
Output is correct |
35 |
Correct |
71 ms |
59636 KB |
Output is correct |
36 |
Correct |
64 ms |
59848 KB |
Output is correct |
37 |
Correct |
73 ms |
59520 KB |
Output is correct |
38 |
Correct |
64 ms |
59528 KB |
Output is correct |
39 |
Correct |
64 ms |
59084 KB |
Output is correct |
40 |
Correct |
58 ms |
56260 KB |
Output is correct |
41 |
Correct |
66 ms |
59848 KB |
Output is correct |
42 |
Correct |
63 ms |
59792 KB |
Output is correct |
43 |
Correct |
60 ms |
63688 KB |
Output is correct |
44 |
Correct |
71 ms |
60032 KB |
Output is correct |
45 |
Correct |
78 ms |
57028 KB |
Output is correct |
46 |
Correct |
62 ms |
59588 KB |
Output is correct |
47 |
Correct |
65 ms |
59624 KB |
Output is correct |
48 |
Correct |
71 ms |
61384 KB |
Output is correct |
49 |
Correct |
58 ms |
41484 KB |
Output is correct |
50 |
Correct |
50 ms |
40480 KB |
Output is correct |
51 |
Correct |
66 ms |
52936 KB |
Output is correct |
52 |
Correct |
93 ms |
63936 KB |
Output is correct |
53 |
Correct |
99 ms |
64560 KB |
Output is correct |
54 |
Correct |
98 ms |
65052 KB |
Output is correct |
55 |
Correct |
60 ms |
63176 KB |
Output is correct |
56 |
Correct |
110 ms |
65212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31324 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
7 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31324 KB |
Output is correct |
5 |
Correct |
7 ms |
31356 KB |
Output is correct |
6 |
Correct |
7 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31324 KB |
Output is correct |
9 |
Correct |
51 ms |
50372 KB |
Output is correct |
10 |
Correct |
72 ms |
55936 KB |
Output is correct |
11 |
Correct |
61 ms |
55772 KB |
Output is correct |
12 |
Correct |
64 ms |
58568 KB |
Output is correct |
13 |
Correct |
60 ms |
61704 KB |
Output is correct |
14 |
Correct |
56 ms |
50888 KB |
Output is correct |
15 |
Correct |
121 ms |
61628 KB |
Output is correct |
16 |
Correct |
123 ms |
59236 KB |
Output is correct |
17 |
Correct |
126 ms |
62084 KB |
Output is correct |
18 |
Correct |
161 ms |
65124 KB |
Output is correct |
19 |
Incorrect |
143 ms |
67220 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
33372 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31324 KB |
Output is correct |
5 |
Correct |
7 ms |
31324 KB |
Output is correct |
6 |
Correct |
7 ms |
31356 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31324 KB |
Output is correct |
9 |
Correct |
7 ms |
31324 KB |
Output is correct |
10 |
Correct |
51 ms |
50372 KB |
Output is correct |
11 |
Correct |
72 ms |
55936 KB |
Output is correct |
12 |
Correct |
61 ms |
55772 KB |
Output is correct |
13 |
Correct |
64 ms |
58568 KB |
Output is correct |
14 |
Correct |
60 ms |
61704 KB |
Output is correct |
15 |
Correct |
56 ms |
50888 KB |
Output is correct |
16 |
Correct |
121 ms |
61628 KB |
Output is correct |
17 |
Correct |
123 ms |
59236 KB |
Output is correct |
18 |
Correct |
126 ms |
62084 KB |
Output is correct |
19 |
Correct |
161 ms |
65124 KB |
Output is correct |
20 |
Incorrect |
143 ms |
67220 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |