//happier ending for folks like us?
//yani in AC nashe, yak yak kesaii ke in APIO dadan dast ma
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 15, M = 2e5 + 5, L = 21, INF = 0x3f3f3f3f;
int p[N], dpr[N], pr[N][L], ext[N], P[N], h[N], rt, D[N], deg[N];
vector<int> adj[N], Wtmp;
inline void smin(int &a, int b) {a = min(a, b);}
void dfs(int v) {
for (int i = 1; i < L; i++) pr[v][i] = pr[pr[v][i - 1]][i - 1];
for (auto u: adj[v]) {
pr[u][0] = v;
h[u] = h[v] + 1;
dfs(u);
smin(ext[v], ext[u]);
}
}
int gpr(int u) {return dpr[u] == u ? u : dpr[u] = gpr(dpr[u]);}
bool merge(int u, int v, int id) {
int tu = u, tv = v;
deg[tu]++, deg[tv]++;
u = gpr(u), v = gpr(v);
if (u == v) return false;
dpr[u] = dpr[v] = id + M;
D[id + M] = max({D[u], D[v], deg[tu], deg[tv]});
adj[id + M].push_back(u);
adj[id + M].push_back(v);
return true;
}
void init(int n, int m, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
iota(p, p + m, 0);
sort(p, p + m, [&](const int x, const int y) {return W[x] < W[y];});
iota(dpr, dpr + N, 0);
memset(ext, 0x3f, sizeof ext);
Wtmp = W;
for (int i = 0; i < m; i++) {
const int id = p[i];
if (!merge(U[id], V[id], id)) {
smin(ext[U[id]], W[id]);
smin(ext[V[id]], W[id]);
}
}
rt = gpr(0), pr[rt][0] = rt, dfs(rt);
}
inline bool check(int O) {return D[O] > 2 || ext[O] < INF;}
int getMinimumFuelCapacity(int X, int Y) {
if (h[X] < h[Y]) swap(X, Y);
while (h[Y] < h[X]) X = pr[X][__lg(h[X] - h[Y])];
for (int i = L - 1; i >= 0; i--) if (pr[Y][i] != pr[X][i] || !check(pr[X][i])) {
Y = pr[Y][i], X = pr[X][i];
}
int lca = pr[X][0], w = Wtmp[lca - M];
if (D[lca] > 2) return w;
w = max(w, ext[lca]);
return w >= INF ? -1 : w;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12756 KB |
Output is correct |
2 |
Correct |
8 ms |
12884 KB |
Output is correct |
3 |
Correct |
8 ms |
12884 KB |
Output is correct |
4 |
Correct |
10 ms |
12884 KB |
Output is correct |
5 |
Correct |
8 ms |
13040 KB |
Output is correct |
6 |
Correct |
10 ms |
13044 KB |
Output is correct |
7 |
Correct |
11 ms |
13140 KB |
Output is correct |
8 |
Correct |
8 ms |
13052 KB |
Output is correct |
9 |
Correct |
106 ms |
32464 KB |
Output is correct |
10 |
Correct |
151 ms |
36824 KB |
Output is correct |
11 |
Correct |
162 ms |
36300 KB |
Output is correct |
12 |
Correct |
143 ms |
37772 KB |
Output is correct |
13 |
Correct |
185 ms |
41776 KB |
Output is correct |
14 |
Correct |
119 ms |
32772 KB |
Output is correct |
15 |
Correct |
246 ms |
39140 KB |
Output is correct |
16 |
Correct |
259 ms |
38448 KB |
Output is correct |
17 |
Correct |
274 ms |
39976 KB |
Output is correct |
18 |
Correct |
368 ms |
43760 KB |
Output is correct |
19 |
Correct |
109 ms |
20800 KB |
Output is correct |
20 |
Correct |
255 ms |
42848 KB |
Output is correct |
21 |
Correct |
265 ms |
42184 KB |
Output is correct |
22 |
Correct |
288 ms |
43692 KB |
Output is correct |
23 |
Correct |
441 ms |
47596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12756 KB |
Output is correct |
2 |
Correct |
8 ms |
12884 KB |
Output is correct |
3 |
Correct |
409 ms |
47304 KB |
Output is correct |
4 |
Correct |
444 ms |
50348 KB |
Output is correct |
5 |
Correct |
386 ms |
49632 KB |
Output is correct |
6 |
Correct |
369 ms |
50156 KB |
Output is correct |
7 |
Correct |
399 ms |
50000 KB |
Output is correct |
8 |
Correct |
432 ms |
48824 KB |
Output is correct |
9 |
Correct |
424 ms |
49688 KB |
Output is correct |
10 |
Correct |
390 ms |
48324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12756 KB |
Output is correct |
2 |
Correct |
8 ms |
12884 KB |
Output is correct |
3 |
Correct |
8 ms |
12884 KB |
Output is correct |
4 |
Correct |
10 ms |
12884 KB |
Output is correct |
5 |
Correct |
8 ms |
13040 KB |
Output is correct |
6 |
Correct |
10 ms |
13044 KB |
Output is correct |
7 |
Correct |
11 ms |
13140 KB |
Output is correct |
8 |
Correct |
8 ms |
13052 KB |
Output is correct |
9 |
Correct |
8 ms |
12884 KB |
Output is correct |
10 |
Correct |
8 ms |
13064 KB |
Output is correct |
11 |
Correct |
10 ms |
13012 KB |
Output is correct |
12 |
Correct |
8 ms |
13040 KB |
Output is correct |
13 |
Correct |
8 ms |
13036 KB |
Output is correct |
14 |
Correct |
8 ms |
13040 KB |
Output is correct |
15 |
Correct |
8 ms |
13012 KB |
Output is correct |
16 |
Correct |
8 ms |
13012 KB |
Output is correct |
17 |
Correct |
9 ms |
13168 KB |
Output is correct |
18 |
Correct |
8 ms |
13044 KB |
Output is correct |
19 |
Correct |
8 ms |
13012 KB |
Output is correct |
20 |
Correct |
8 ms |
13012 KB |
Output is correct |
21 |
Correct |
8 ms |
13140 KB |
Output is correct |
22 |
Correct |
8 ms |
13140 KB |
Output is correct |
23 |
Correct |
8 ms |
12968 KB |
Output is correct |
24 |
Incorrect |
8 ms |
13140 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12884 KB |
Output is correct |
2 |
Correct |
7 ms |
12756 KB |
Output is correct |
3 |
Correct |
8 ms |
12884 KB |
Output is correct |
4 |
Correct |
8 ms |
12884 KB |
Output is correct |
5 |
Correct |
10 ms |
12884 KB |
Output is correct |
6 |
Correct |
8 ms |
13040 KB |
Output is correct |
7 |
Correct |
10 ms |
13044 KB |
Output is correct |
8 |
Correct |
11 ms |
13140 KB |
Output is correct |
9 |
Correct |
8 ms |
13052 KB |
Output is correct |
10 |
Correct |
106 ms |
32464 KB |
Output is correct |
11 |
Correct |
151 ms |
36824 KB |
Output is correct |
12 |
Correct |
162 ms |
36300 KB |
Output is correct |
13 |
Correct |
143 ms |
37772 KB |
Output is correct |
14 |
Correct |
185 ms |
41776 KB |
Output is correct |
15 |
Correct |
8 ms |
13064 KB |
Output is correct |
16 |
Correct |
10 ms |
13012 KB |
Output is correct |
17 |
Correct |
8 ms |
13040 KB |
Output is correct |
18 |
Correct |
8 ms |
13036 KB |
Output is correct |
19 |
Correct |
8 ms |
13040 KB |
Output is correct |
20 |
Correct |
8 ms |
13012 KB |
Output is correct |
21 |
Correct |
8 ms |
13012 KB |
Output is correct |
22 |
Correct |
9 ms |
13168 KB |
Output is correct |
23 |
Correct |
8 ms |
13044 KB |
Output is correct |
24 |
Correct |
8 ms |
13012 KB |
Output is correct |
25 |
Correct |
8 ms |
13012 KB |
Output is correct |
26 |
Correct |
8 ms |
13140 KB |
Output is correct |
27 |
Correct |
8 ms |
13140 KB |
Output is correct |
28 |
Correct |
8 ms |
12968 KB |
Output is correct |
29 |
Incorrect |
8 ms |
13140 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12756 KB |
Output is correct |
2 |
Correct |
8 ms |
12884 KB |
Output is correct |
3 |
Correct |
8 ms |
12884 KB |
Output is correct |
4 |
Correct |
10 ms |
12884 KB |
Output is correct |
5 |
Correct |
8 ms |
13040 KB |
Output is correct |
6 |
Correct |
10 ms |
13044 KB |
Output is correct |
7 |
Correct |
11 ms |
13140 KB |
Output is correct |
8 |
Correct |
8 ms |
13052 KB |
Output is correct |
9 |
Correct |
106 ms |
32464 KB |
Output is correct |
10 |
Correct |
151 ms |
36824 KB |
Output is correct |
11 |
Correct |
162 ms |
36300 KB |
Output is correct |
12 |
Correct |
143 ms |
37772 KB |
Output is correct |
13 |
Correct |
185 ms |
41776 KB |
Output is correct |
14 |
Correct |
119 ms |
32772 KB |
Output is correct |
15 |
Correct |
246 ms |
39140 KB |
Output is correct |
16 |
Correct |
259 ms |
38448 KB |
Output is correct |
17 |
Correct |
274 ms |
39976 KB |
Output is correct |
18 |
Correct |
368 ms |
43760 KB |
Output is correct |
19 |
Correct |
409 ms |
47304 KB |
Output is correct |
20 |
Correct |
444 ms |
50348 KB |
Output is correct |
21 |
Correct |
386 ms |
49632 KB |
Output is correct |
22 |
Correct |
369 ms |
50156 KB |
Output is correct |
23 |
Correct |
399 ms |
50000 KB |
Output is correct |
24 |
Correct |
432 ms |
48824 KB |
Output is correct |
25 |
Correct |
424 ms |
49688 KB |
Output is correct |
26 |
Correct |
390 ms |
48324 KB |
Output is correct |
27 |
Correct |
8 ms |
13064 KB |
Output is correct |
28 |
Correct |
10 ms |
13012 KB |
Output is correct |
29 |
Correct |
8 ms |
13040 KB |
Output is correct |
30 |
Correct |
8 ms |
13036 KB |
Output is correct |
31 |
Correct |
8 ms |
13040 KB |
Output is correct |
32 |
Correct |
8 ms |
13012 KB |
Output is correct |
33 |
Correct |
8 ms |
13012 KB |
Output is correct |
34 |
Correct |
9 ms |
13168 KB |
Output is correct |
35 |
Correct |
8 ms |
13044 KB |
Output is correct |
36 |
Correct |
18 ms |
16340 KB |
Output is correct |
37 |
Correct |
136 ms |
38956 KB |
Output is correct |
38 |
Correct |
130 ms |
38888 KB |
Output is correct |
39 |
Correct |
143 ms |
39016 KB |
Output is correct |
40 |
Correct |
132 ms |
38504 KB |
Output is correct |
41 |
Correct |
125 ms |
38464 KB |
Output is correct |
42 |
Correct |
118 ms |
36320 KB |
Output is correct |
43 |
Correct |
150 ms |
39128 KB |
Output is correct |
44 |
Correct |
127 ms |
38860 KB |
Output is correct |
45 |
Correct |
150 ms |
44020 KB |
Output is correct |
46 |
Correct |
133 ms |
39320 KB |
Output is correct |
47 |
Correct |
27 ms |
16588 KB |
Output is correct |
48 |
Correct |
238 ms |
43828 KB |
Output is correct |
49 |
Correct |
269 ms |
43840 KB |
Output is correct |
50 |
Correct |
246 ms |
43868 KB |
Output is correct |
51 |
Correct |
282 ms |
43636 KB |
Output is correct |
52 |
Correct |
233 ms |
42060 KB |
Output is correct |
53 |
Correct |
240 ms |
36132 KB |
Output is correct |
54 |
Correct |
248 ms |
44620 KB |
Output is correct |
55 |
Correct |
243 ms |
43764 KB |
Output is correct |
56 |
Correct |
408 ms |
47788 KB |
Output is correct |
57 |
Correct |
274 ms |
44748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12884 KB |
Output is correct |
2 |
Correct |
7 ms |
12756 KB |
Output is correct |
3 |
Correct |
8 ms |
12884 KB |
Output is correct |
4 |
Correct |
8 ms |
12884 KB |
Output is correct |
5 |
Correct |
10 ms |
12884 KB |
Output is correct |
6 |
Correct |
8 ms |
13040 KB |
Output is correct |
7 |
Correct |
10 ms |
13044 KB |
Output is correct |
8 |
Correct |
11 ms |
13140 KB |
Output is correct |
9 |
Correct |
8 ms |
13052 KB |
Output is correct |
10 |
Correct |
106 ms |
32464 KB |
Output is correct |
11 |
Correct |
151 ms |
36824 KB |
Output is correct |
12 |
Correct |
162 ms |
36300 KB |
Output is correct |
13 |
Correct |
143 ms |
37772 KB |
Output is correct |
14 |
Correct |
185 ms |
41776 KB |
Output is correct |
15 |
Correct |
119 ms |
32772 KB |
Output is correct |
16 |
Correct |
246 ms |
39140 KB |
Output is correct |
17 |
Correct |
259 ms |
38448 KB |
Output is correct |
18 |
Correct |
274 ms |
39976 KB |
Output is correct |
19 |
Correct |
368 ms |
43760 KB |
Output is correct |
20 |
Correct |
409 ms |
47304 KB |
Output is correct |
21 |
Correct |
444 ms |
50348 KB |
Output is correct |
22 |
Correct |
386 ms |
49632 KB |
Output is correct |
23 |
Correct |
369 ms |
50156 KB |
Output is correct |
24 |
Correct |
399 ms |
50000 KB |
Output is correct |
25 |
Correct |
432 ms |
48824 KB |
Output is correct |
26 |
Correct |
424 ms |
49688 KB |
Output is correct |
27 |
Correct |
390 ms |
48324 KB |
Output is correct |
28 |
Correct |
8 ms |
13064 KB |
Output is correct |
29 |
Correct |
10 ms |
13012 KB |
Output is correct |
30 |
Correct |
8 ms |
13040 KB |
Output is correct |
31 |
Correct |
8 ms |
13036 KB |
Output is correct |
32 |
Correct |
8 ms |
13040 KB |
Output is correct |
33 |
Correct |
8 ms |
13012 KB |
Output is correct |
34 |
Correct |
8 ms |
13012 KB |
Output is correct |
35 |
Correct |
9 ms |
13168 KB |
Output is correct |
36 |
Correct |
8 ms |
13044 KB |
Output is correct |
37 |
Correct |
18 ms |
16340 KB |
Output is correct |
38 |
Correct |
136 ms |
38956 KB |
Output is correct |
39 |
Correct |
130 ms |
38888 KB |
Output is correct |
40 |
Correct |
143 ms |
39016 KB |
Output is correct |
41 |
Correct |
132 ms |
38504 KB |
Output is correct |
42 |
Correct |
125 ms |
38464 KB |
Output is correct |
43 |
Correct |
118 ms |
36320 KB |
Output is correct |
44 |
Correct |
150 ms |
39128 KB |
Output is correct |
45 |
Correct |
127 ms |
38860 KB |
Output is correct |
46 |
Correct |
150 ms |
44020 KB |
Output is correct |
47 |
Correct |
133 ms |
39320 KB |
Output is correct |
48 |
Correct |
27 ms |
16588 KB |
Output is correct |
49 |
Correct |
238 ms |
43828 KB |
Output is correct |
50 |
Correct |
269 ms |
43840 KB |
Output is correct |
51 |
Correct |
246 ms |
43868 KB |
Output is correct |
52 |
Correct |
282 ms |
43636 KB |
Output is correct |
53 |
Correct |
233 ms |
42060 KB |
Output is correct |
54 |
Correct |
240 ms |
36132 KB |
Output is correct |
55 |
Correct |
248 ms |
44620 KB |
Output is correct |
56 |
Correct |
243 ms |
43764 KB |
Output is correct |
57 |
Correct |
408 ms |
47788 KB |
Output is correct |
58 |
Correct |
274 ms |
44748 KB |
Output is correct |
59 |
Correct |
109 ms |
20800 KB |
Output is correct |
60 |
Correct |
255 ms |
42848 KB |
Output is correct |
61 |
Correct |
265 ms |
42184 KB |
Output is correct |
62 |
Correct |
288 ms |
43692 KB |
Output is correct |
63 |
Correct |
441 ms |
47596 KB |
Output is correct |
64 |
Correct |
8 ms |
13012 KB |
Output is correct |
65 |
Correct |
8 ms |
13012 KB |
Output is correct |
66 |
Correct |
8 ms |
13140 KB |
Output is correct |
67 |
Correct |
8 ms |
13140 KB |
Output is correct |
68 |
Correct |
8 ms |
12968 KB |
Output is correct |
69 |
Incorrect |
8 ms |
13140 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |