Submission #743656

# Submission time Handle Problem Language Result Execution time Memory
743656 2023-05-17T15:40:40 Z RushB Swapping Cities (APIO20_swap) C++17
36 / 100
443 ms 47724 KB
//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 = ext[lca];
	return w >= INF ? -1 : w;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12756 KB Output is correct
2 Correct 7 ms 12840 KB Output is correct
3 Correct 6 ms 12756 KB Output is correct
4 Correct 7 ms 12920 KB Output is correct
5 Correct 8 ms 13012 KB Output is correct
6 Correct 7 ms 13012 KB Output is correct
7 Correct 8 ms 13012 KB Output is correct
8 Correct 7 ms 13140 KB Output is correct
9 Correct 99 ms 31908 KB Output is correct
10 Correct 137 ms 36292 KB Output is correct
11 Correct 122 ms 35688 KB Output is correct
12 Correct 129 ms 37136 KB Output is correct
13 Correct 154 ms 41036 KB Output is correct
14 Correct 115 ms 32012 KB Output is correct
15 Correct 234 ms 38064 KB Output is correct
16 Correct 233 ms 37500 KB Output is correct
17 Correct 250 ms 38828 KB Output is correct
18 Correct 388 ms 42784 KB Output is correct
19 Correct 98 ms 20072 KB Output is correct
20 Correct 231 ms 39360 KB Output is correct
21 Correct 236 ms 38628 KB Output is correct
22 Correct 256 ms 40220 KB Output is correct
23 Correct 443 ms 44148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12756 KB Output is correct
2 Correct 7 ms 12840 KB Output is correct
3 Correct 362 ms 46152 KB Output is correct
4 Correct 359 ms 47724 KB Output is correct
5 Correct 367 ms 46848 KB Output is correct
6 Correct 344 ms 47544 KB Output is correct
7 Correct 385 ms 47364 KB Output is correct
8 Correct 398 ms 46016 KB Output is correct
9 Correct 392 ms 47040 KB Output is correct
10 Correct 375 ms 45720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12756 KB Output is correct
2 Correct 7 ms 12840 KB Output is correct
3 Correct 6 ms 12756 KB Output is correct
4 Correct 7 ms 12920 KB Output is correct
5 Correct 8 ms 13012 KB Output is correct
6 Correct 7 ms 13012 KB Output is correct
7 Correct 8 ms 13012 KB Output is correct
8 Correct 7 ms 13140 KB Output is correct
9 Correct 7 ms 12756 KB Output is correct
10 Correct 10 ms 13012 KB Output is correct
11 Correct 7 ms 13012 KB Output is correct
12 Correct 8 ms 13012 KB Output is correct
13 Correct 7 ms 13012 KB Output is correct
14 Correct 8 ms 12992 KB Output is correct
15 Correct 8 ms 13012 KB Output is correct
16 Correct 8 ms 13116 KB Output is correct
17 Correct 8 ms 13140 KB Output is correct
18 Correct 11 ms 13112 KB Output is correct
19 Correct 9 ms 13012 KB Output is correct
20 Correct 9 ms 13012 KB Output is correct
21 Correct 8 ms 13012 KB Output is correct
22 Correct 8 ms 13048 KB Output is correct
23 Correct 7 ms 13052 KB Output is correct
24 Incorrect 9 ms 13164 KB Output isn't correct
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12756 KB Output is correct
2 Correct 9 ms 12756 KB Output is correct
3 Correct 7 ms 12840 KB Output is correct
4 Correct 6 ms 12756 KB Output is correct
5 Correct 7 ms 12920 KB Output is correct
6 Correct 8 ms 13012 KB Output is correct
7 Correct 7 ms 13012 KB Output is correct
8 Correct 8 ms 13012 KB Output is correct
9 Correct 7 ms 13140 KB Output is correct
10 Correct 99 ms 31908 KB Output is correct
11 Correct 137 ms 36292 KB Output is correct
12 Correct 122 ms 35688 KB Output is correct
13 Correct 129 ms 37136 KB Output is correct
14 Correct 154 ms 41036 KB Output is correct
15 Correct 10 ms 13012 KB Output is correct
16 Correct 7 ms 13012 KB Output is correct
17 Correct 8 ms 13012 KB Output is correct
18 Correct 7 ms 13012 KB Output is correct
19 Correct 8 ms 12992 KB Output is correct
20 Correct 8 ms 13012 KB Output is correct
21 Correct 8 ms 13116 KB Output is correct
22 Correct 8 ms 13140 KB Output is correct
23 Correct 11 ms 13112 KB Output is correct
24 Correct 9 ms 13012 KB Output is correct
25 Correct 9 ms 13012 KB Output is correct
26 Correct 8 ms 13012 KB Output is correct
27 Correct 8 ms 13048 KB Output is correct
28 Correct 7 ms 13052 KB Output is correct
29 Incorrect 9 ms 13164 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12756 KB Output is correct
2 Correct 7 ms 12840 KB Output is correct
3 Correct 6 ms 12756 KB Output is correct
4 Correct 7 ms 12920 KB Output is correct
5 Correct 8 ms 13012 KB Output is correct
6 Correct 7 ms 13012 KB Output is correct
7 Correct 8 ms 13012 KB Output is correct
8 Correct 7 ms 13140 KB Output is correct
9 Correct 99 ms 31908 KB Output is correct
10 Correct 137 ms 36292 KB Output is correct
11 Correct 122 ms 35688 KB Output is correct
12 Correct 129 ms 37136 KB Output is correct
13 Correct 154 ms 41036 KB Output is correct
14 Correct 115 ms 32012 KB Output is correct
15 Correct 234 ms 38064 KB Output is correct
16 Correct 233 ms 37500 KB Output is correct
17 Correct 250 ms 38828 KB Output is correct
18 Correct 388 ms 42784 KB Output is correct
19 Correct 362 ms 46152 KB Output is correct
20 Correct 359 ms 47724 KB Output is correct
21 Correct 367 ms 46848 KB Output is correct
22 Correct 344 ms 47544 KB Output is correct
23 Correct 385 ms 47364 KB Output is correct
24 Correct 398 ms 46016 KB Output is correct
25 Correct 392 ms 47040 KB Output is correct
26 Correct 375 ms 45720 KB Output is correct
27 Correct 10 ms 13012 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 13012 KB Output is correct
31 Correct 8 ms 12992 KB Output is correct
32 Correct 8 ms 13012 KB Output is correct
33 Correct 8 ms 13116 KB Output is correct
34 Correct 8 ms 13140 KB Output is correct
35 Correct 11 ms 13112 KB Output is correct
36 Correct 19 ms 16132 KB Output is correct
37 Correct 134 ms 37132 KB Output is correct
38 Correct 136 ms 37120 KB Output is correct
39 Correct 134 ms 37096 KB Output is correct
40 Correct 133 ms 36812 KB Output is correct
41 Correct 154 ms 36556 KB Output is correct
42 Correct 127 ms 34636 KB Output is correct
43 Correct 133 ms 37136 KB Output is correct
44 Correct 129 ms 37240 KB Output is correct
45 Correct 161 ms 42368 KB Output is correct
46 Correct 133 ms 37112 KB Output is correct
47 Correct 25 ms 16104 KB Output is correct
48 Correct 238 ms 39644 KB Output is correct
49 Correct 240 ms 39644 KB Output is correct
50 Correct 250 ms 39560 KB Output is correct
51 Correct 274 ms 39668 KB Output is correct
52 Correct 220 ms 38140 KB Output is correct
53 Correct 188 ms 32508 KB Output is correct
54 Correct 276 ms 40244 KB Output is correct
55 Correct 240 ms 39680 KB Output is correct
56 Correct 400 ms 43788 KB Output is correct
57 Correct 293 ms 40292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12756 KB Output is correct
2 Correct 9 ms 12756 KB Output is correct
3 Correct 7 ms 12840 KB Output is correct
4 Correct 6 ms 12756 KB Output is correct
5 Correct 7 ms 12920 KB Output is correct
6 Correct 8 ms 13012 KB Output is correct
7 Correct 7 ms 13012 KB Output is correct
8 Correct 8 ms 13012 KB Output is correct
9 Correct 7 ms 13140 KB Output is correct
10 Correct 99 ms 31908 KB Output is correct
11 Correct 137 ms 36292 KB Output is correct
12 Correct 122 ms 35688 KB Output is correct
13 Correct 129 ms 37136 KB Output is correct
14 Correct 154 ms 41036 KB Output is correct
15 Correct 115 ms 32012 KB Output is correct
16 Correct 234 ms 38064 KB Output is correct
17 Correct 233 ms 37500 KB Output is correct
18 Correct 250 ms 38828 KB Output is correct
19 Correct 388 ms 42784 KB Output is correct
20 Correct 362 ms 46152 KB Output is correct
21 Correct 359 ms 47724 KB Output is correct
22 Correct 367 ms 46848 KB Output is correct
23 Correct 344 ms 47544 KB Output is correct
24 Correct 385 ms 47364 KB Output is correct
25 Correct 398 ms 46016 KB Output is correct
26 Correct 392 ms 47040 KB Output is correct
27 Correct 375 ms 45720 KB Output is correct
28 Correct 10 ms 13012 KB Output is correct
29 Correct 7 ms 13012 KB Output is correct
30 Correct 8 ms 13012 KB Output is correct
31 Correct 7 ms 13012 KB Output is correct
32 Correct 8 ms 12992 KB Output is correct
33 Correct 8 ms 13012 KB Output is correct
34 Correct 8 ms 13116 KB Output is correct
35 Correct 8 ms 13140 KB Output is correct
36 Correct 11 ms 13112 KB Output is correct
37 Correct 19 ms 16132 KB Output is correct
38 Correct 134 ms 37132 KB Output is correct
39 Correct 136 ms 37120 KB Output is correct
40 Correct 134 ms 37096 KB Output is correct
41 Correct 133 ms 36812 KB Output is correct
42 Correct 154 ms 36556 KB Output is correct
43 Correct 127 ms 34636 KB Output is correct
44 Correct 133 ms 37136 KB Output is correct
45 Correct 129 ms 37240 KB Output is correct
46 Correct 161 ms 42368 KB Output is correct
47 Correct 133 ms 37112 KB Output is correct
48 Correct 25 ms 16104 KB Output is correct
49 Correct 238 ms 39644 KB Output is correct
50 Correct 240 ms 39644 KB Output is correct
51 Correct 250 ms 39560 KB Output is correct
52 Correct 274 ms 39668 KB Output is correct
53 Correct 220 ms 38140 KB Output is correct
54 Correct 188 ms 32508 KB Output is correct
55 Correct 276 ms 40244 KB Output is correct
56 Correct 240 ms 39680 KB Output is correct
57 Correct 400 ms 43788 KB Output is correct
58 Correct 293 ms 40292 KB Output is correct
59 Correct 98 ms 20072 KB Output is correct
60 Correct 231 ms 39360 KB Output is correct
61 Correct 236 ms 38628 KB Output is correct
62 Correct 256 ms 40220 KB Output is correct
63 Correct 443 ms 44148 KB Output is correct
64 Correct 9 ms 13012 KB Output is correct
65 Correct 9 ms 13012 KB Output is correct
66 Correct 8 ms 13012 KB Output is correct
67 Correct 8 ms 13048 KB Output is correct
68 Correct 7 ms 13052 KB Output is correct
69 Incorrect 9 ms 13164 KB Output isn't correct
70 Halted 0 ms 0 KB -