//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);
}
int ans2(int X, int Y) {
for (int i = L - 1; i >= 0; i--) if (pr[Y][i] != pr[X][i] && ext[pr[X][i]] >= INF) Y = pr[Y][i], X = pr[X][i];
return max(Wtmp[pr[X][0] - M], ext[pr[X][0]]);
}
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])];
int w = ans2(X, Y);
for (int i = L - 1; i >= 0; i--) if (pr[Y][i] != pr[X][i] || D[pr[X][i]] <= 2) Y = pr[Y][i], X = pr[X][i];
smin(w, (D[pr[X][0]] > 2 ? Wtmp[pr[X][0] - M] : INF));
return w >= INF ? -1 : w;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12756 KB |
Output is correct |
2 |
Correct |
6 ms |
12756 KB |
Output is correct |
3 |
Correct |
7 ms |
12756 KB |
Output is correct |
4 |
Correct |
7 ms |
12884 KB |
Output is correct |
5 |
Correct |
8 ms |
13012 KB |
Output is correct |
6 |
Correct |
7 ms |
13012 KB |
Output is correct |
7 |
Correct |
10 ms |
13012 KB |
Output is correct |
8 |
Correct |
7 ms |
13140 KB |
Output is correct |
9 |
Correct |
103 ms |
31868 KB |
Output is correct |
10 |
Correct |
121 ms |
36052 KB |
Output is correct |
11 |
Correct |
137 ms |
35788 KB |
Output is correct |
12 |
Correct |
161 ms |
37120 KB |
Output is correct |
13 |
Correct |
149 ms |
41048 KB |
Output is correct |
14 |
Correct |
113 ms |
32004 KB |
Output is correct |
15 |
Correct |
267 ms |
38108 KB |
Output is correct |
16 |
Correct |
262 ms |
37428 KB |
Output is correct |
17 |
Correct |
286 ms |
38876 KB |
Output is correct |
18 |
Correct |
430 ms |
42732 KB |
Output is correct |
19 |
Incorrect |
108 ms |
19336 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12756 KB |
Output is correct |
2 |
Correct |
6 ms |
12756 KB |
Output is correct |
3 |
Correct |
441 ms |
46224 KB |
Output is correct |
4 |
Correct |
421 ms |
47732 KB |
Output is correct |
5 |
Correct |
437 ms |
46848 KB |
Output is correct |
6 |
Correct |
435 ms |
47544 KB |
Output is correct |
7 |
Correct |
419 ms |
47300 KB |
Output is correct |
8 |
Correct |
391 ms |
46012 KB |
Output is correct |
9 |
Correct |
415 ms |
46976 KB |
Output is correct |
10 |
Correct |
394 ms |
45716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12756 KB |
Output is correct |
2 |
Correct |
6 ms |
12756 KB |
Output is correct |
3 |
Correct |
7 ms |
12756 KB |
Output is correct |
4 |
Correct |
7 ms |
12884 KB |
Output is correct |
5 |
Correct |
8 ms |
13012 KB |
Output is correct |
6 |
Correct |
7 ms |
13012 KB |
Output is correct |
7 |
Correct |
10 ms |
13012 KB |
Output is correct |
8 |
Correct |
7 ms |
13140 KB |
Output is correct |
9 |
Correct |
7 ms |
12764 KB |
Output is correct |
10 |
Correct |
7 ms |
13012 KB |
Output is correct |
11 |
Correct |
8 ms |
13012 KB |
Output is correct |
12 |
Correct |
7 ms |
13112 KB |
Output is correct |
13 |
Correct |
8 ms |
13012 KB |
Output is correct |
14 |
Correct |
8 ms |
13020 KB |
Output is correct |
15 |
Correct |
8 ms |
13012 KB |
Output is correct |
16 |
Correct |
8 ms |
13056 KB |
Output is correct |
17 |
Correct |
8 ms |
13140 KB |
Output is correct |
18 |
Correct |
7 ms |
13012 KB |
Output is correct |
19 |
Incorrect |
7 ms |
13012 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12764 KB |
Output is correct |
2 |
Correct |
8 ms |
12756 KB |
Output is correct |
3 |
Correct |
6 ms |
12756 KB |
Output is correct |
4 |
Correct |
7 ms |
12756 KB |
Output is correct |
5 |
Correct |
7 ms |
12884 KB |
Output is correct |
6 |
Correct |
8 ms |
13012 KB |
Output is correct |
7 |
Correct |
7 ms |
13012 KB |
Output is correct |
8 |
Correct |
10 ms |
13012 KB |
Output is correct |
9 |
Correct |
7 ms |
13140 KB |
Output is correct |
10 |
Correct |
103 ms |
31868 KB |
Output is correct |
11 |
Correct |
121 ms |
36052 KB |
Output is correct |
12 |
Correct |
137 ms |
35788 KB |
Output is correct |
13 |
Correct |
161 ms |
37120 KB |
Output is correct |
14 |
Correct |
149 ms |
41048 KB |
Output is correct |
15 |
Correct |
7 ms |
13012 KB |
Output is correct |
16 |
Correct |
8 ms |
13012 KB |
Output is correct |
17 |
Correct |
7 ms |
13112 KB |
Output is correct |
18 |
Correct |
8 ms |
13012 KB |
Output is correct |
19 |
Correct |
8 ms |
13020 KB |
Output is correct |
20 |
Correct |
8 ms |
13012 KB |
Output is correct |
21 |
Correct |
8 ms |
13056 KB |
Output is correct |
22 |
Correct |
8 ms |
13140 KB |
Output is correct |
23 |
Correct |
7 ms |
13012 KB |
Output is correct |
24 |
Incorrect |
7 ms |
13012 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12756 KB |
Output is correct |
2 |
Correct |
6 ms |
12756 KB |
Output is correct |
3 |
Correct |
7 ms |
12756 KB |
Output is correct |
4 |
Correct |
7 ms |
12884 KB |
Output is correct |
5 |
Correct |
8 ms |
13012 KB |
Output is correct |
6 |
Correct |
7 ms |
13012 KB |
Output is correct |
7 |
Correct |
10 ms |
13012 KB |
Output is correct |
8 |
Correct |
7 ms |
13140 KB |
Output is correct |
9 |
Correct |
103 ms |
31868 KB |
Output is correct |
10 |
Correct |
121 ms |
36052 KB |
Output is correct |
11 |
Correct |
137 ms |
35788 KB |
Output is correct |
12 |
Correct |
161 ms |
37120 KB |
Output is correct |
13 |
Correct |
149 ms |
41048 KB |
Output is correct |
14 |
Correct |
113 ms |
32004 KB |
Output is correct |
15 |
Correct |
267 ms |
38108 KB |
Output is correct |
16 |
Correct |
262 ms |
37428 KB |
Output is correct |
17 |
Correct |
286 ms |
38876 KB |
Output is correct |
18 |
Correct |
430 ms |
42732 KB |
Output is correct |
19 |
Correct |
441 ms |
46224 KB |
Output is correct |
20 |
Correct |
421 ms |
47732 KB |
Output is correct |
21 |
Correct |
437 ms |
46848 KB |
Output is correct |
22 |
Correct |
435 ms |
47544 KB |
Output is correct |
23 |
Correct |
419 ms |
47300 KB |
Output is correct |
24 |
Correct |
391 ms |
46012 KB |
Output is correct |
25 |
Correct |
415 ms |
46976 KB |
Output is correct |
26 |
Correct |
394 ms |
45716 KB |
Output is correct |
27 |
Correct |
7 ms |
13012 KB |
Output is correct |
28 |
Correct |
8 ms |
13012 KB |
Output is correct |
29 |
Correct |
7 ms |
13112 KB |
Output is correct |
30 |
Correct |
8 ms |
13012 KB |
Output is correct |
31 |
Correct |
8 ms |
13020 KB |
Output is correct |
32 |
Correct |
8 ms |
13012 KB |
Output is correct |
33 |
Correct |
8 ms |
13056 KB |
Output is correct |
34 |
Correct |
8 ms |
13140 KB |
Output is correct |
35 |
Correct |
7 ms |
13012 KB |
Output is correct |
36 |
Correct |
18 ms |
16236 KB |
Output is correct |
37 |
Correct |
123 ms |
37068 KB |
Output is correct |
38 |
Correct |
122 ms |
37064 KB |
Output is correct |
39 |
Correct |
140 ms |
37104 KB |
Output is correct |
40 |
Correct |
135 ms |
36728 KB |
Output is correct |
41 |
Correct |
131 ms |
36592 KB |
Output is correct |
42 |
Correct |
122 ms |
34740 KB |
Output is correct |
43 |
Correct |
160 ms |
37132 KB |
Output is correct |
44 |
Correct |
121 ms |
37068 KB |
Output is correct |
45 |
Correct |
150 ms |
42236 KB |
Output is correct |
46 |
Correct |
137 ms |
37080 KB |
Output is correct |
47 |
Correct |
35 ms |
16128 KB |
Output is correct |
48 |
Correct |
265 ms |
39716 KB |
Output is correct |
49 |
Correct |
279 ms |
39680 KB |
Output is correct |
50 |
Correct |
267 ms |
39552 KB |
Output is correct |
51 |
Correct |
280 ms |
39416 KB |
Output is correct |
52 |
Correct |
274 ms |
38088 KB |
Output is correct |
53 |
Correct |
252 ms |
32612 KB |
Output is correct |
54 |
Correct |
280 ms |
40228 KB |
Output is correct |
55 |
Correct |
307 ms |
39808 KB |
Output is correct |
56 |
Correct |
487 ms |
43700 KB |
Output is correct |
57 |
Correct |
316 ms |
40328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12764 KB |
Output is correct |
2 |
Correct |
8 ms |
12756 KB |
Output is correct |
3 |
Correct |
6 ms |
12756 KB |
Output is correct |
4 |
Correct |
7 ms |
12756 KB |
Output is correct |
5 |
Correct |
7 ms |
12884 KB |
Output is correct |
6 |
Correct |
8 ms |
13012 KB |
Output is correct |
7 |
Correct |
7 ms |
13012 KB |
Output is correct |
8 |
Correct |
10 ms |
13012 KB |
Output is correct |
9 |
Correct |
7 ms |
13140 KB |
Output is correct |
10 |
Correct |
103 ms |
31868 KB |
Output is correct |
11 |
Correct |
121 ms |
36052 KB |
Output is correct |
12 |
Correct |
137 ms |
35788 KB |
Output is correct |
13 |
Correct |
161 ms |
37120 KB |
Output is correct |
14 |
Correct |
149 ms |
41048 KB |
Output is correct |
15 |
Correct |
113 ms |
32004 KB |
Output is correct |
16 |
Correct |
267 ms |
38108 KB |
Output is correct |
17 |
Correct |
262 ms |
37428 KB |
Output is correct |
18 |
Correct |
286 ms |
38876 KB |
Output is correct |
19 |
Correct |
430 ms |
42732 KB |
Output is correct |
20 |
Correct |
441 ms |
46224 KB |
Output is correct |
21 |
Correct |
421 ms |
47732 KB |
Output is correct |
22 |
Correct |
437 ms |
46848 KB |
Output is correct |
23 |
Correct |
435 ms |
47544 KB |
Output is correct |
24 |
Correct |
419 ms |
47300 KB |
Output is correct |
25 |
Correct |
391 ms |
46012 KB |
Output is correct |
26 |
Correct |
415 ms |
46976 KB |
Output is correct |
27 |
Correct |
394 ms |
45716 KB |
Output is correct |
28 |
Correct |
7 ms |
13012 KB |
Output is correct |
29 |
Correct |
8 ms |
13012 KB |
Output is correct |
30 |
Correct |
7 ms |
13112 KB |
Output is correct |
31 |
Correct |
8 ms |
13012 KB |
Output is correct |
32 |
Correct |
8 ms |
13020 KB |
Output is correct |
33 |
Correct |
8 ms |
13012 KB |
Output is correct |
34 |
Correct |
8 ms |
13056 KB |
Output is correct |
35 |
Correct |
8 ms |
13140 KB |
Output is correct |
36 |
Correct |
7 ms |
13012 KB |
Output is correct |
37 |
Correct |
18 ms |
16236 KB |
Output is correct |
38 |
Correct |
123 ms |
37068 KB |
Output is correct |
39 |
Correct |
122 ms |
37064 KB |
Output is correct |
40 |
Correct |
140 ms |
37104 KB |
Output is correct |
41 |
Correct |
135 ms |
36728 KB |
Output is correct |
42 |
Correct |
131 ms |
36592 KB |
Output is correct |
43 |
Correct |
122 ms |
34740 KB |
Output is correct |
44 |
Correct |
160 ms |
37132 KB |
Output is correct |
45 |
Correct |
121 ms |
37068 KB |
Output is correct |
46 |
Correct |
150 ms |
42236 KB |
Output is correct |
47 |
Correct |
137 ms |
37080 KB |
Output is correct |
48 |
Correct |
35 ms |
16128 KB |
Output is correct |
49 |
Correct |
265 ms |
39716 KB |
Output is correct |
50 |
Correct |
279 ms |
39680 KB |
Output is correct |
51 |
Correct |
267 ms |
39552 KB |
Output is correct |
52 |
Correct |
280 ms |
39416 KB |
Output is correct |
53 |
Correct |
274 ms |
38088 KB |
Output is correct |
54 |
Correct |
252 ms |
32612 KB |
Output is correct |
55 |
Correct |
280 ms |
40228 KB |
Output is correct |
56 |
Correct |
307 ms |
39808 KB |
Output is correct |
57 |
Correct |
487 ms |
43700 KB |
Output is correct |
58 |
Correct |
316 ms |
40328 KB |
Output is correct |
59 |
Incorrect |
108 ms |
19336 KB |
Output isn't correct |
60 |
Halted |
0 ms |
0 KB |
- |