//happier ending for folks like us?
#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] = id + M;
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 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])
Y = pr[Y][i], X = pr[X][i];
int lca = pr[X][0], l = lca - M, w = Wtmp[l];
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 |
7 ms |
12812 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 |
8 ms |
13088 KB |
Output is correct |
7 |
Correct |
8 ms |
13060 KB |
Output is correct |
8 |
Correct |
9 ms |
13140 KB |
Output is correct |
9 |
Correct |
109 ms |
31912 KB |
Output is correct |
10 |
Correct |
134 ms |
36168 KB |
Output is correct |
11 |
Correct |
126 ms |
35724 KB |
Output is correct |
12 |
Correct |
145 ms |
37140 KB |
Output is correct |
13 |
Correct |
178 ms |
41036 KB |
Output is correct |
14 |
Correct |
112 ms |
31936 KB |
Output is correct |
15 |
Correct |
227 ms |
38156 KB |
Output is correct |
16 |
Correct |
253 ms |
37436 KB |
Output is correct |
17 |
Correct |
235 ms |
38824 KB |
Output is correct |
18 |
Correct |
436 ms |
42756 KB |
Output is correct |
19 |
Incorrect |
86 ms |
19340 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12756 KB |
Output is correct |
2 |
Correct |
7 ms |
12812 KB |
Output is correct |
3 |
Incorrect |
363 ms |
46148 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12756 KB |
Output is correct |
2 |
Correct |
7 ms |
12812 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 |
8 ms |
13088 KB |
Output is correct |
7 |
Correct |
8 ms |
13060 KB |
Output is correct |
8 |
Correct |
9 ms |
13140 KB |
Output is correct |
9 |
Correct |
7 ms |
12756 KB |
Output is correct |
10 |
Correct |
8 ms |
13012 KB |
Output is correct |
11 |
Correct |
8 ms |
13012 KB |
Output is correct |
12 |
Correct |
7 ms |
13012 KB |
Output is correct |
13 |
Correct |
7 ms |
12976 KB |
Output is correct |
14 |
Correct |
7 ms |
13012 KB |
Output is correct |
15 |
Incorrect |
8 ms |
13012 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12756 KB |
Output is correct |
2 |
Correct |
7 ms |
12756 KB |
Output is correct |
3 |
Correct |
7 ms |
12812 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 |
8 ms |
13088 KB |
Output is correct |
8 |
Correct |
8 ms |
13060 KB |
Output is correct |
9 |
Correct |
9 ms |
13140 KB |
Output is correct |
10 |
Correct |
109 ms |
31912 KB |
Output is correct |
11 |
Correct |
134 ms |
36168 KB |
Output is correct |
12 |
Correct |
126 ms |
35724 KB |
Output is correct |
13 |
Correct |
145 ms |
37140 KB |
Output is correct |
14 |
Correct |
178 ms |
41036 KB |
Output is correct |
15 |
Correct |
8 ms |
13012 KB |
Output is correct |
16 |
Correct |
8 ms |
13012 KB |
Output is correct |
17 |
Correct |
7 ms |
13012 KB |
Output is correct |
18 |
Correct |
7 ms |
12976 KB |
Output is correct |
19 |
Correct |
7 ms |
13012 KB |
Output is correct |
20 |
Incorrect |
8 ms |
13012 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12756 KB |
Output is correct |
2 |
Correct |
7 ms |
12812 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 |
8 ms |
13088 KB |
Output is correct |
7 |
Correct |
8 ms |
13060 KB |
Output is correct |
8 |
Correct |
9 ms |
13140 KB |
Output is correct |
9 |
Correct |
109 ms |
31912 KB |
Output is correct |
10 |
Correct |
134 ms |
36168 KB |
Output is correct |
11 |
Correct |
126 ms |
35724 KB |
Output is correct |
12 |
Correct |
145 ms |
37140 KB |
Output is correct |
13 |
Correct |
178 ms |
41036 KB |
Output is correct |
14 |
Correct |
112 ms |
31936 KB |
Output is correct |
15 |
Correct |
227 ms |
38156 KB |
Output is correct |
16 |
Correct |
253 ms |
37436 KB |
Output is correct |
17 |
Correct |
235 ms |
38824 KB |
Output is correct |
18 |
Correct |
436 ms |
42756 KB |
Output is correct |
19 |
Incorrect |
363 ms |
46148 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12756 KB |
Output is correct |
2 |
Correct |
7 ms |
12756 KB |
Output is correct |
3 |
Correct |
7 ms |
12812 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 |
8 ms |
13088 KB |
Output is correct |
8 |
Correct |
8 ms |
13060 KB |
Output is correct |
9 |
Correct |
9 ms |
13140 KB |
Output is correct |
10 |
Correct |
109 ms |
31912 KB |
Output is correct |
11 |
Correct |
134 ms |
36168 KB |
Output is correct |
12 |
Correct |
126 ms |
35724 KB |
Output is correct |
13 |
Correct |
145 ms |
37140 KB |
Output is correct |
14 |
Correct |
178 ms |
41036 KB |
Output is correct |
15 |
Correct |
112 ms |
31936 KB |
Output is correct |
16 |
Correct |
227 ms |
38156 KB |
Output is correct |
17 |
Correct |
253 ms |
37436 KB |
Output is correct |
18 |
Correct |
235 ms |
38824 KB |
Output is correct |
19 |
Correct |
436 ms |
42756 KB |
Output is correct |
20 |
Incorrect |
363 ms |
46148 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |