Submission #743680

# Submission time Handle Problem Language Result Execution time Memory
743680 2023-05-17T17:13:38 Z RushB Swapping Cities (APIO20_swap) C++17
30 / 100
521 ms 48060 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);
}
int ans2(int X, int Y) {
	for (int i = L - 1; i >= 0; i--) if (pr[Y][i] != pr[X][i]) 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 7 ms 12756 KB Output is correct
2 Correct 8 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 10 ms 13012 KB Output is correct
6 Correct 7 ms 13012 KB Output is correct
7 Correct 8 ms 13008 KB Output is correct
8 Correct 9 ms 13140 KB Output is correct
9 Correct 118 ms 31968 KB Output is correct
10 Correct 127 ms 36168 KB Output is correct
11 Correct 122 ms 35748 KB Output is correct
12 Correct 137 ms 37196 KB Output is correct
13 Correct 161 ms 41112 KB Output is correct
14 Correct 111 ms 32012 KB Output is correct
15 Correct 261 ms 38112 KB Output is correct
16 Correct 280 ms 37500 KB Output is correct
17 Correct 270 ms 38944 KB Output is correct
18 Correct 445 ms 42740 KB Output is correct
19 Incorrect 105 ms 19360 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 8 ms 12756 KB Output is correct
3 Correct 488 ms 46148 KB Output is correct
4 Correct 411 ms 48052 KB Output is correct
5 Correct 447 ms 47204 KB Output is correct
6 Correct 429 ms 48060 KB Output is correct
7 Correct 455 ms 47792 KB Output is correct
8 Correct 436 ms 46472 KB Output is correct
9 Correct 521 ms 47356 KB Output is correct
10 Correct 441 ms 46224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12756 KB Output is correct
2 Correct 8 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 10 ms 13012 KB Output is correct
6 Correct 7 ms 13012 KB Output is correct
7 Correct 8 ms 13008 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 13044 KB Output is correct
11 Correct 8 ms 13012 KB Output is correct
12 Correct 9 ms 13012 KB Output is correct
13 Correct 8 ms 13056 KB Output is correct
14 Correct 8 ms 13012 KB Output is correct
15 Correct 10 ms 13044 KB Output is correct
16 Correct 10 ms 13080 KB Output is correct
17 Correct 8 ms 13172 KB Output is correct
18 Correct 8 ms 13136 KB Output is correct
19 Correct 9 ms 13044 KB Output is correct
20 Correct 8 ms 13012 KB Output is correct
21 Correct 8 ms 13148 KB Output is correct
22 Correct 9 ms 13048 KB Output is correct
23 Correct 8 ms 13012 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 7 ms 12756 KB Output is correct
2 Correct 7 ms 12756 KB Output is correct
3 Correct 8 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 10 ms 13012 KB Output is correct
7 Correct 7 ms 13012 KB Output is correct
8 Correct 8 ms 13008 KB Output is correct
9 Correct 9 ms 13140 KB Output is correct
10 Correct 118 ms 31968 KB Output is correct
11 Correct 127 ms 36168 KB Output is correct
12 Correct 122 ms 35748 KB Output is correct
13 Correct 137 ms 37196 KB Output is correct
14 Correct 161 ms 41112 KB Output is correct
15 Correct 8 ms 13044 KB Output is correct
16 Correct 8 ms 13012 KB Output is correct
17 Correct 9 ms 13012 KB Output is correct
18 Correct 8 ms 13056 KB Output is correct
19 Correct 8 ms 13012 KB Output is correct
20 Correct 10 ms 13044 KB Output is correct
21 Correct 10 ms 13080 KB Output is correct
22 Correct 8 ms 13172 KB Output is correct
23 Correct 8 ms 13136 KB Output is correct
24 Correct 9 ms 13044 KB Output is correct
25 Correct 8 ms 13012 KB Output is correct
26 Correct 8 ms 13148 KB Output is correct
27 Correct 9 ms 13048 KB Output is correct
28 Correct 8 ms 13012 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 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 10 ms 13012 KB Output is correct
6 Correct 7 ms 13012 KB Output is correct
7 Correct 8 ms 13008 KB Output is correct
8 Correct 9 ms 13140 KB Output is correct
9 Correct 118 ms 31968 KB Output is correct
10 Correct 127 ms 36168 KB Output is correct
11 Correct 122 ms 35748 KB Output is correct
12 Correct 137 ms 37196 KB Output is correct
13 Correct 161 ms 41112 KB Output is correct
14 Correct 111 ms 32012 KB Output is correct
15 Correct 261 ms 38112 KB Output is correct
16 Correct 280 ms 37500 KB Output is correct
17 Correct 270 ms 38944 KB Output is correct
18 Correct 445 ms 42740 KB Output is correct
19 Correct 488 ms 46148 KB Output is correct
20 Correct 411 ms 48052 KB Output is correct
21 Correct 447 ms 47204 KB Output is correct
22 Correct 429 ms 48060 KB Output is correct
23 Correct 455 ms 47792 KB Output is correct
24 Correct 436 ms 46472 KB Output is correct
25 Correct 521 ms 47356 KB Output is correct
26 Correct 441 ms 46224 KB Output is correct
27 Correct 8 ms 13044 KB Output is correct
28 Correct 8 ms 13012 KB Output is correct
29 Correct 9 ms 13012 KB Output is correct
30 Correct 8 ms 13056 KB Output is correct
31 Correct 8 ms 13012 KB Output is correct
32 Correct 10 ms 13044 KB Output is correct
33 Correct 10 ms 13080 KB Output is correct
34 Correct 8 ms 13172 KB Output is correct
35 Correct 8 ms 13136 KB Output is correct
36 Correct 19 ms 16332 KB Output is correct
37 Correct 142 ms 37884 KB Output is correct
38 Correct 135 ms 37832 KB Output is correct
39 Correct 139 ms 37772 KB Output is correct
40 Correct 155 ms 37580 KB Output is correct
41 Correct 127 ms 37360 KB Output is correct
42 Correct 117 ms 35496 KB Output is correct
43 Correct 148 ms 38032 KB Output is correct
44 Correct 132 ms 37880 KB Output is correct
45 Correct 166 ms 43104 KB Output is correct
46 Correct 148 ms 37960 KB Output is correct
47 Correct 32 ms 16540 KB Output is correct
48 Correct 280 ms 40672 KB Output is correct
49 Correct 290 ms 40616 KB Output is correct
50 Correct 287 ms 40588 KB Output is correct
51 Correct 280 ms 40256 KB Output is correct
52 Correct 264 ms 38940 KB Output is correct
53 Correct 235 ms 33344 KB Output is correct
54 Correct 299 ms 41136 KB Output is correct
55 Correct 263 ms 40404 KB Output is correct
56 Correct 426 ms 44520 KB Output is correct
57 Correct 332 ms 41176 KB Output is correct
# 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 8 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 10 ms 13012 KB Output is correct
7 Correct 7 ms 13012 KB Output is correct
8 Correct 8 ms 13008 KB Output is correct
9 Correct 9 ms 13140 KB Output is correct
10 Correct 118 ms 31968 KB Output is correct
11 Correct 127 ms 36168 KB Output is correct
12 Correct 122 ms 35748 KB Output is correct
13 Correct 137 ms 37196 KB Output is correct
14 Correct 161 ms 41112 KB Output is correct
15 Correct 111 ms 32012 KB Output is correct
16 Correct 261 ms 38112 KB Output is correct
17 Correct 280 ms 37500 KB Output is correct
18 Correct 270 ms 38944 KB Output is correct
19 Correct 445 ms 42740 KB Output is correct
20 Correct 488 ms 46148 KB Output is correct
21 Correct 411 ms 48052 KB Output is correct
22 Correct 447 ms 47204 KB Output is correct
23 Correct 429 ms 48060 KB Output is correct
24 Correct 455 ms 47792 KB Output is correct
25 Correct 436 ms 46472 KB Output is correct
26 Correct 521 ms 47356 KB Output is correct
27 Correct 441 ms 46224 KB Output is correct
28 Correct 8 ms 13044 KB Output is correct
29 Correct 8 ms 13012 KB Output is correct
30 Correct 9 ms 13012 KB Output is correct
31 Correct 8 ms 13056 KB Output is correct
32 Correct 8 ms 13012 KB Output is correct
33 Correct 10 ms 13044 KB Output is correct
34 Correct 10 ms 13080 KB Output is correct
35 Correct 8 ms 13172 KB Output is correct
36 Correct 8 ms 13136 KB Output is correct
37 Correct 19 ms 16332 KB Output is correct
38 Correct 142 ms 37884 KB Output is correct
39 Correct 135 ms 37832 KB Output is correct
40 Correct 139 ms 37772 KB Output is correct
41 Correct 155 ms 37580 KB Output is correct
42 Correct 127 ms 37360 KB Output is correct
43 Correct 117 ms 35496 KB Output is correct
44 Correct 148 ms 38032 KB Output is correct
45 Correct 132 ms 37880 KB Output is correct
46 Correct 166 ms 43104 KB Output is correct
47 Correct 148 ms 37960 KB Output is correct
48 Correct 32 ms 16540 KB Output is correct
49 Correct 280 ms 40672 KB Output is correct
50 Correct 290 ms 40616 KB Output is correct
51 Correct 287 ms 40588 KB Output is correct
52 Correct 280 ms 40256 KB Output is correct
53 Correct 264 ms 38940 KB Output is correct
54 Correct 235 ms 33344 KB Output is correct
55 Correct 299 ms 41136 KB Output is correct
56 Correct 263 ms 40404 KB Output is correct
57 Correct 426 ms 44520 KB Output is correct
58 Correct 332 ms 41176 KB Output is correct
59 Incorrect 105 ms 19360 KB Output isn't correct
60 Halted 0 ms 0 KB -