답안 #922122

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922122 2024-02-05T05:58:46 Z 406 자매 도시 (APIO20_swap) C++17
100 / 100
428 ms 57204 KB
    //happier ending for folks like us? 
    //yani in AC nashe, yak yak kesaii ke in APIO dadan dast ma
    //PAIN
    #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 LCA(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 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 = INF, lca = LCA(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));
    	if (h[X] <= h[lca]) smin(w, max(Wtmp[X - M], ext[X]));
    	return w >= INF ? -1 : w;
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12888 KB Output is correct
2 Correct 7 ms 12892 KB Output is correct
3 Correct 8 ms 12892 KB Output is correct
4 Correct 7 ms 12892 KB Output is correct
5 Correct 7 ms 13148 KB Output is correct
6 Correct 8 ms 13148 KB Output is correct
7 Correct 7 ms 13196 KB Output is correct
8 Correct 10 ms 13148 KB Output is correct
9 Correct 92 ms 33712 KB Output is correct
10 Correct 125 ms 38332 KB Output is correct
11 Correct 125 ms 37700 KB Output is correct
12 Correct 151 ms 39396 KB Output is correct
13 Correct 140 ms 43096 KB Output is correct
14 Correct 113 ms 33996 KB Output is correct
15 Correct 252 ms 42524 KB Output is correct
16 Correct 255 ms 41856 KB Output is correct
17 Correct 229 ms 43380 KB Output is correct
18 Correct 388 ms 47304 KB Output is correct
19 Correct 97 ms 22104 KB Output is correct
20 Correct 269 ms 43728 KB Output is correct
21 Correct 231 ms 43284 KB Output is correct
22 Correct 303 ms 44816 KB Output is correct
23 Correct 320 ms 48732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12888 KB Output is correct
2 Correct 7 ms 12892 KB Output is correct
3 Correct 306 ms 50132 KB Output is correct
4 Correct 299 ms 51640 KB Output is correct
5 Correct 311 ms 50804 KB Output is correct
6 Correct 311 ms 51508 KB Output is correct
7 Correct 372 ms 51276 KB Output is correct
8 Correct 403 ms 49868 KB Output is correct
9 Correct 302 ms 50948 KB Output is correct
10 Correct 324 ms 49684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12888 KB Output is correct
2 Correct 7 ms 12892 KB Output is correct
3 Correct 8 ms 12892 KB Output is correct
4 Correct 7 ms 12892 KB Output is correct
5 Correct 7 ms 13148 KB Output is correct
6 Correct 8 ms 13148 KB Output is correct
7 Correct 7 ms 13196 KB Output is correct
8 Correct 10 ms 13148 KB Output is correct
9 Correct 7 ms 12892 KB Output is correct
10 Correct 9 ms 13156 KB Output is correct
11 Correct 8 ms 13148 KB Output is correct
12 Correct 7 ms 13148 KB Output is correct
13 Correct 7 ms 13148 KB Output is correct
14 Correct 9 ms 13148 KB Output is correct
15 Correct 7 ms 13148 KB Output is correct
16 Correct 7 ms 13148 KB Output is correct
17 Correct 7 ms 13144 KB Output is correct
18 Correct 7 ms 13148 KB Output is correct
19 Correct 7 ms 13148 KB Output is correct
20 Correct 7 ms 13144 KB Output is correct
21 Correct 7 ms 13148 KB Output is correct
22 Correct 7 ms 13148 KB Output is correct
23 Correct 7 ms 13148 KB Output is correct
24 Correct 7 ms 13148 KB Output is correct
25 Correct 7 ms 13148 KB Output is correct
26 Correct 7 ms 13404 KB Output is correct
27 Correct 7 ms 13144 KB Output is correct
28 Correct 7 ms 13404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12892 KB Output is correct
2 Correct 7 ms 12888 KB Output is correct
3 Correct 7 ms 12892 KB Output is correct
4 Correct 8 ms 12892 KB Output is correct
5 Correct 7 ms 12892 KB Output is correct
6 Correct 7 ms 13148 KB Output is correct
7 Correct 8 ms 13148 KB Output is correct
8 Correct 7 ms 13196 KB Output is correct
9 Correct 10 ms 13148 KB Output is correct
10 Correct 92 ms 33712 KB Output is correct
11 Correct 125 ms 38332 KB Output is correct
12 Correct 125 ms 37700 KB Output is correct
13 Correct 151 ms 39396 KB Output is correct
14 Correct 140 ms 43096 KB Output is correct
15 Correct 9 ms 13156 KB Output is correct
16 Correct 8 ms 13148 KB Output is correct
17 Correct 7 ms 13148 KB Output is correct
18 Correct 7 ms 13148 KB Output is correct
19 Correct 9 ms 13148 KB Output is correct
20 Correct 7 ms 13148 KB Output is correct
21 Correct 7 ms 13148 KB Output is correct
22 Correct 7 ms 13144 KB Output is correct
23 Correct 7 ms 13148 KB Output is correct
24 Correct 7 ms 13148 KB Output is correct
25 Correct 7 ms 13144 KB Output is correct
26 Correct 7 ms 13148 KB Output is correct
27 Correct 7 ms 13148 KB Output is correct
28 Correct 7 ms 13148 KB Output is correct
29 Correct 7 ms 13148 KB Output is correct
30 Correct 7 ms 13148 KB Output is correct
31 Correct 7 ms 13404 KB Output is correct
32 Correct 7 ms 13144 KB Output is correct
33 Correct 7 ms 13404 KB Output is correct
34 Correct 18 ms 16508 KB Output is correct
35 Correct 137 ms 39292 KB Output is correct
36 Correct 124 ms 38996 KB Output is correct
37 Correct 122 ms 39032 KB Output is correct
38 Correct 134 ms 38728 KB Output is correct
39 Correct 132 ms 38480 KB Output is correct
40 Correct 105 ms 36472 KB Output is correct
41 Correct 148 ms 39272 KB Output is correct
42 Correct 131 ms 39104 KB Output is correct
43 Correct 136 ms 44096 KB Output is correct
44 Correct 131 ms 39456 KB Output is correct
45 Correct 155 ms 45400 KB Output is correct
46 Correct 127 ms 38996 KB Output is correct
47 Correct 135 ms 38984 KB Output is correct
48 Correct 141 ms 42232 KB Output is correct
49 Correct 58 ms 25888 KB Output is correct
50 Correct 52 ms 30548 KB Output is correct
51 Correct 130 ms 40436 KB Output is correct
52 Correct 161 ms 48072 KB Output is correct
53 Correct 190 ms 51616 KB Output is correct
54 Correct 168 ms 53352 KB Output is correct
55 Correct 128 ms 43744 KB Output is correct
56 Correct 177 ms 51808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12888 KB Output is correct
2 Correct 7 ms 12892 KB Output is correct
3 Correct 8 ms 12892 KB Output is correct
4 Correct 7 ms 12892 KB Output is correct
5 Correct 7 ms 13148 KB Output is correct
6 Correct 8 ms 13148 KB Output is correct
7 Correct 7 ms 13196 KB Output is correct
8 Correct 10 ms 13148 KB Output is correct
9 Correct 92 ms 33712 KB Output is correct
10 Correct 125 ms 38332 KB Output is correct
11 Correct 125 ms 37700 KB Output is correct
12 Correct 151 ms 39396 KB Output is correct
13 Correct 140 ms 43096 KB Output is correct
14 Correct 113 ms 33996 KB Output is correct
15 Correct 252 ms 42524 KB Output is correct
16 Correct 255 ms 41856 KB Output is correct
17 Correct 229 ms 43380 KB Output is correct
18 Correct 388 ms 47304 KB Output is correct
19 Correct 306 ms 50132 KB Output is correct
20 Correct 299 ms 51640 KB Output is correct
21 Correct 311 ms 50804 KB Output is correct
22 Correct 311 ms 51508 KB Output is correct
23 Correct 372 ms 51276 KB Output is correct
24 Correct 403 ms 49868 KB Output is correct
25 Correct 302 ms 50948 KB Output is correct
26 Correct 324 ms 49684 KB Output is correct
27 Correct 9 ms 13156 KB Output is correct
28 Correct 8 ms 13148 KB Output is correct
29 Correct 7 ms 13148 KB Output is correct
30 Correct 7 ms 13148 KB Output is correct
31 Correct 9 ms 13148 KB Output is correct
32 Correct 7 ms 13148 KB Output is correct
33 Correct 7 ms 13148 KB Output is correct
34 Correct 7 ms 13144 KB Output is correct
35 Correct 7 ms 13148 KB Output is correct
36 Correct 18 ms 16508 KB Output is correct
37 Correct 137 ms 39292 KB Output is correct
38 Correct 124 ms 38996 KB Output is correct
39 Correct 122 ms 39032 KB Output is correct
40 Correct 134 ms 38728 KB Output is correct
41 Correct 132 ms 38480 KB Output is correct
42 Correct 105 ms 36472 KB Output is correct
43 Correct 148 ms 39272 KB Output is correct
44 Correct 131 ms 39104 KB Output is correct
45 Correct 136 ms 44096 KB Output is correct
46 Correct 131 ms 39456 KB Output is correct
47 Correct 34 ms 16736 KB Output is correct
48 Correct 240 ms 43908 KB Output is correct
49 Correct 281 ms 44024 KB Output is correct
50 Correct 231 ms 43780 KB Output is correct
51 Correct 262 ms 43764 KB Output is correct
52 Correct 216 ms 42204 KB Output is correct
53 Correct 190 ms 36144 KB Output is correct
54 Correct 251 ms 44880 KB Output is correct
55 Correct 297 ms 43868 KB Output is correct
56 Correct 326 ms 47948 KB Output is correct
57 Correct 271 ms 44948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 12892 KB Output is correct
2 Correct 7 ms 12888 KB Output is correct
3 Correct 7 ms 12892 KB Output is correct
4 Correct 8 ms 12892 KB Output is correct
5 Correct 7 ms 12892 KB Output is correct
6 Correct 7 ms 13148 KB Output is correct
7 Correct 8 ms 13148 KB Output is correct
8 Correct 7 ms 13196 KB Output is correct
9 Correct 10 ms 13148 KB Output is correct
10 Correct 92 ms 33712 KB Output is correct
11 Correct 125 ms 38332 KB Output is correct
12 Correct 125 ms 37700 KB Output is correct
13 Correct 151 ms 39396 KB Output is correct
14 Correct 140 ms 43096 KB Output is correct
15 Correct 113 ms 33996 KB Output is correct
16 Correct 252 ms 42524 KB Output is correct
17 Correct 255 ms 41856 KB Output is correct
18 Correct 229 ms 43380 KB Output is correct
19 Correct 388 ms 47304 KB Output is correct
20 Correct 306 ms 50132 KB Output is correct
21 Correct 299 ms 51640 KB Output is correct
22 Correct 311 ms 50804 KB Output is correct
23 Correct 311 ms 51508 KB Output is correct
24 Correct 372 ms 51276 KB Output is correct
25 Correct 403 ms 49868 KB Output is correct
26 Correct 302 ms 50948 KB Output is correct
27 Correct 324 ms 49684 KB Output is correct
28 Correct 9 ms 13156 KB Output is correct
29 Correct 8 ms 13148 KB Output is correct
30 Correct 7 ms 13148 KB Output is correct
31 Correct 7 ms 13148 KB Output is correct
32 Correct 9 ms 13148 KB Output is correct
33 Correct 7 ms 13148 KB Output is correct
34 Correct 7 ms 13148 KB Output is correct
35 Correct 7 ms 13144 KB Output is correct
36 Correct 7 ms 13148 KB Output is correct
37 Correct 18 ms 16508 KB Output is correct
38 Correct 137 ms 39292 KB Output is correct
39 Correct 124 ms 38996 KB Output is correct
40 Correct 122 ms 39032 KB Output is correct
41 Correct 134 ms 38728 KB Output is correct
42 Correct 132 ms 38480 KB Output is correct
43 Correct 105 ms 36472 KB Output is correct
44 Correct 148 ms 39272 KB Output is correct
45 Correct 131 ms 39104 KB Output is correct
46 Correct 136 ms 44096 KB Output is correct
47 Correct 131 ms 39456 KB Output is correct
48 Correct 34 ms 16736 KB Output is correct
49 Correct 240 ms 43908 KB Output is correct
50 Correct 281 ms 44024 KB Output is correct
51 Correct 231 ms 43780 KB Output is correct
52 Correct 262 ms 43764 KB Output is correct
53 Correct 216 ms 42204 KB Output is correct
54 Correct 190 ms 36144 KB Output is correct
55 Correct 251 ms 44880 KB Output is correct
56 Correct 297 ms 43868 KB Output is correct
57 Correct 326 ms 47948 KB Output is correct
58 Correct 271 ms 44948 KB Output is correct
59 Correct 97 ms 22104 KB Output is correct
60 Correct 269 ms 43728 KB Output is correct
61 Correct 231 ms 43284 KB Output is correct
62 Correct 303 ms 44816 KB Output is correct
63 Correct 320 ms 48732 KB Output is correct
64 Correct 7 ms 13148 KB Output is correct
65 Correct 7 ms 13144 KB Output is correct
66 Correct 7 ms 13148 KB Output is correct
67 Correct 7 ms 13148 KB Output is correct
68 Correct 7 ms 13148 KB Output is correct
69 Correct 7 ms 13148 KB Output is correct
70 Correct 7 ms 13148 KB Output is correct
71 Correct 7 ms 13404 KB Output is correct
72 Correct 7 ms 13144 KB Output is correct
73 Correct 7 ms 13404 KB Output is correct
74 Correct 155 ms 45400 KB Output is correct
75 Correct 127 ms 38996 KB Output is correct
76 Correct 135 ms 38984 KB Output is correct
77 Correct 141 ms 42232 KB Output is correct
78 Correct 58 ms 25888 KB Output is correct
79 Correct 52 ms 30548 KB Output is correct
80 Correct 130 ms 40436 KB Output is correct
81 Correct 161 ms 48072 KB Output is correct
82 Correct 190 ms 51616 KB Output is correct
83 Correct 168 ms 53352 KB Output is correct
84 Correct 128 ms 43744 KB Output is correct
85 Correct 177 ms 51808 KB Output is correct
86 Correct 77 ms 25672 KB Output is correct
87 Correct 237 ms 43864 KB Output is correct
88 Correct 236 ms 43848 KB Output is correct
89 Correct 320 ms 45540 KB Output is correct
90 Correct 158 ms 32176 KB Output is correct
91 Correct 192 ms 39900 KB Output is correct
92 Correct 285 ms 44744 KB Output is correct
93 Correct 304 ms 52340 KB Output is correct
94 Correct 337 ms 55456 KB Output is correct
95 Correct 301 ms 57204 KB Output is correct
96 Correct 370 ms 48344 KB Output is correct
97 Correct 428 ms 51404 KB Output is correct