Submission #935164

# Submission time Handle Problem Language Result Execution time Memory
935164 2024-02-28T18:11:14 Z MinaRagy06 Swapping Cities (APIO20_swap) C++17
100 / 100
540 ms 57976 KB
#include <bits/stdc++.h>
#ifdef MINA
#include "grader.cpp"
#endif
using namespace std;
#define ll long long

const int N = 200'005;
int n, m;
array<int, 3> e[N];
vector<array<int, 2>> par[N], sz[N], mx[N], cnt[N];
int deg[N];
int get(vector<array<int, 2>> &v, int t) {
	int l = 0, r = v.size() - 1;
	while (l <= r) {
		int md = ((l + r) >> 1);
		if (v[md][1] <= t) {
			l = md + 1;
		} else {
			r = md - 1;
		}
	}
	return v[r][0];
}
int find(int u, int t) {
	int p = get(par[u], t);
	if (p == u) {
		return u;
	}
	return find(p, t);
}
void join(int u, int v, int t) {
	int du = ++deg[u], dv = ++deg[v];
	u = find(u, t), v = find(v, t);
	mx[u].push_back({max(mx[u].back()[0], du), t});
	mx[v].push_back({max(mx[v].back()[0], dv), t});
	cnt[u].push_back({cnt[u].back()[0] + 1, t});
	if (u == v) return;
	if (sz[u].back()[0] < sz[v].back()[0]) swap(u, v);
	par[v].push_back({u, t});
	sz[u].push_back({sz[u].back()[0] + sz[v].back()[0], t});
	cnt[u].push_back({cnt[u].back()[0] + cnt[v].back()[0], t});
	mx[u].push_back({max(mx[u].back()[0], mx[v].back()[0]), t});
}
void init(int _n, int _m, vector<int> u, vector<int> v, vector<int> w) {
	n = _n, m = _m;
	for (int i = 0; i < m; i++) {
		e[i] = {u[i], v[i], w[i]};
	}
	sort(e, e + m, [&] (array<int, 3> x, array<int, 3> y) {return x[2] < y[2];});
	for (int i = 0; i < n; i++) {
		par[i].push_back({i, -1});
		sz[i].push_back({1, -1});
		mx[i].push_back({0, -1});
		cnt[i].push_back({0, -1});
		deg[i] = 0;
	}
	for (int i = 0; i < m; i++) {
		join(e[i][0], e[i][1], i);
	}
}
int getMinimumFuelCapacity(int x, int y) {
	int l = 0, r = m - 1;
	while (l <= r) {
		int md = ((l + r) >> 1);
		int p = find(x, md);
		if (p == find(y, md) && (get(mx[p], md) > 2 || get(cnt[p], md) >= get(sz[p], md))) {
			r = md - 1;
		} else {
			l = md + 1;
		}
	}
	if (l == m) {
		return -1;
	}
	return e[l][2];
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 20828 KB Output is correct
2 Correct 5 ms 20828 KB Output is correct
3 Correct 5 ms 20828 KB Output is correct
4 Correct 5 ms 20828 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 5 ms 21172 KB Output is correct
7 Correct 6 ms 21336 KB Output is correct
8 Correct 5 ms 20972 KB Output is correct
9 Correct 97 ms 40276 KB Output is correct
10 Correct 132 ms 44028 KB Output is correct
11 Correct 129 ms 43860 KB Output is correct
12 Correct 139 ms 45396 KB Output is correct
13 Correct 93 ms 41060 KB Output is correct
14 Correct 136 ms 40272 KB Output is correct
15 Correct 402 ms 49296 KB Output is correct
16 Correct 383 ms 48640 KB Output is correct
17 Correct 392 ms 50100 KB Output is correct
18 Correct 302 ms 45840 KB Output is correct
19 Correct 170 ms 30036 KB Output is correct
20 Correct 374 ms 50296 KB Output is correct
21 Correct 381 ms 49676 KB Output is correct
22 Correct 403 ms 51380 KB Output is correct
23 Correct 291 ms 47664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 20828 KB Output is correct
2 Correct 5 ms 20828 KB Output is correct
3 Correct 294 ms 44148 KB Output is correct
4 Correct 307 ms 46640 KB Output is correct
5 Correct 295 ms 46156 KB Output is correct
6 Correct 287 ms 46472 KB Output is correct
7 Correct 293 ms 46500 KB Output is correct
8 Correct 287 ms 45660 KB Output is correct
9 Correct 289 ms 46248 KB Output is correct
10 Correct 285 ms 45416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 20828 KB Output is correct
2 Correct 5 ms 20828 KB Output is correct
3 Correct 5 ms 20828 KB Output is correct
4 Correct 5 ms 20828 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 5 ms 21172 KB Output is correct
7 Correct 6 ms 21336 KB Output is correct
8 Correct 5 ms 20972 KB Output is correct
9 Correct 4 ms 20824 KB Output is correct
10 Correct 5 ms 21084 KB Output is correct
11 Correct 5 ms 21208 KB Output is correct
12 Correct 6 ms 21084 KB Output is correct
13 Correct 5 ms 20972 KB Output is correct
14 Correct 5 ms 21084 KB Output is correct
15 Correct 6 ms 21084 KB Output is correct
16 Correct 5 ms 21084 KB Output is correct
17 Correct 5 ms 21084 KB Output is correct
18 Correct 5 ms 21188 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 6 ms 20976 KB Output is correct
21 Correct 5 ms 21084 KB Output is correct
22 Correct 5 ms 21084 KB Output is correct
23 Correct 7 ms 20916 KB Output is correct
24 Correct 5 ms 21084 KB Output is correct
25 Correct 6 ms 21084 KB Output is correct
26 Correct 6 ms 21184 KB Output is correct
27 Correct 5 ms 21084 KB Output is correct
28 Correct 6 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20824 KB Output is correct
2 Correct 5 ms 20828 KB Output is correct
3 Correct 5 ms 20828 KB Output is correct
4 Correct 5 ms 20828 KB Output is correct
5 Correct 5 ms 20828 KB Output is correct
6 Correct 5 ms 21084 KB Output is correct
7 Correct 5 ms 21172 KB Output is correct
8 Correct 6 ms 21336 KB Output is correct
9 Correct 5 ms 20972 KB Output is correct
10 Correct 97 ms 40276 KB Output is correct
11 Correct 132 ms 44028 KB Output is correct
12 Correct 129 ms 43860 KB Output is correct
13 Correct 139 ms 45396 KB Output is correct
14 Correct 93 ms 41060 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 5 ms 21208 KB Output is correct
17 Correct 6 ms 21084 KB Output is correct
18 Correct 5 ms 20972 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 6 ms 21084 KB Output is correct
21 Correct 5 ms 21084 KB Output is correct
22 Correct 5 ms 21084 KB Output is correct
23 Correct 5 ms 21188 KB Output is correct
24 Correct 5 ms 21084 KB Output is correct
25 Correct 6 ms 20976 KB Output is correct
26 Correct 5 ms 21084 KB Output is correct
27 Correct 5 ms 21084 KB Output is correct
28 Correct 7 ms 20916 KB Output is correct
29 Correct 5 ms 21084 KB Output is correct
30 Correct 6 ms 21084 KB Output is correct
31 Correct 6 ms 21184 KB Output is correct
32 Correct 5 ms 21084 KB Output is correct
33 Correct 6 ms 21084 KB Output is correct
34 Correct 14 ms 24152 KB Output is correct
35 Correct 140 ms 45140 KB Output is correct
36 Correct 132 ms 45136 KB Output is correct
37 Correct 131 ms 45132 KB Output is correct
38 Correct 136 ms 44932 KB Output is correct
39 Correct 125 ms 44168 KB Output is correct
40 Correct 110 ms 41812 KB Output is correct
41 Correct 135 ms 45136 KB Output is correct
42 Correct 137 ms 45184 KB Output is correct
43 Correct 88 ms 42416 KB Output is correct
44 Correct 129 ms 44256 KB Output is correct
45 Correct 118 ms 43576 KB Output is correct
46 Correct 130 ms 45092 KB Output is correct
47 Correct 141 ms 44884 KB Output is correct
48 Correct 120 ms 44304 KB Output is correct
49 Correct 59 ms 32696 KB Output is correct
50 Correct 52 ms 29700 KB Output is correct
51 Correct 96 ms 39992 KB Output is correct
52 Correct 181 ms 49716 KB Output is correct
53 Correct 184 ms 51524 KB Output is correct
54 Correct 196 ms 52412 KB Output is correct
55 Correct 90 ms 41392 KB Output is correct
56 Correct 157 ms 48576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 20828 KB Output is correct
2 Correct 5 ms 20828 KB Output is correct
3 Correct 5 ms 20828 KB Output is correct
4 Correct 5 ms 20828 KB Output is correct
5 Correct 5 ms 21084 KB Output is correct
6 Correct 5 ms 21172 KB Output is correct
7 Correct 6 ms 21336 KB Output is correct
8 Correct 5 ms 20972 KB Output is correct
9 Correct 97 ms 40276 KB Output is correct
10 Correct 132 ms 44028 KB Output is correct
11 Correct 129 ms 43860 KB Output is correct
12 Correct 139 ms 45396 KB Output is correct
13 Correct 93 ms 41060 KB Output is correct
14 Correct 136 ms 40272 KB Output is correct
15 Correct 402 ms 49296 KB Output is correct
16 Correct 383 ms 48640 KB Output is correct
17 Correct 392 ms 50100 KB Output is correct
18 Correct 302 ms 45840 KB Output is correct
19 Correct 294 ms 44148 KB Output is correct
20 Correct 307 ms 46640 KB Output is correct
21 Correct 295 ms 46156 KB Output is correct
22 Correct 287 ms 46472 KB Output is correct
23 Correct 293 ms 46500 KB Output is correct
24 Correct 287 ms 45660 KB Output is correct
25 Correct 289 ms 46248 KB Output is correct
26 Correct 285 ms 45416 KB Output is correct
27 Correct 5 ms 21084 KB Output is correct
28 Correct 5 ms 21208 KB Output is correct
29 Correct 6 ms 21084 KB Output is correct
30 Correct 5 ms 20972 KB Output is correct
31 Correct 5 ms 21084 KB Output is correct
32 Correct 6 ms 21084 KB Output is correct
33 Correct 5 ms 21084 KB Output is correct
34 Correct 5 ms 21084 KB Output is correct
35 Correct 5 ms 21188 KB Output is correct
36 Correct 14 ms 24152 KB Output is correct
37 Correct 140 ms 45140 KB Output is correct
38 Correct 132 ms 45136 KB Output is correct
39 Correct 131 ms 45132 KB Output is correct
40 Correct 136 ms 44932 KB Output is correct
41 Correct 125 ms 44168 KB Output is correct
42 Correct 110 ms 41812 KB Output is correct
43 Correct 135 ms 45136 KB Output is correct
44 Correct 137 ms 45184 KB Output is correct
45 Correct 88 ms 42416 KB Output is correct
46 Correct 129 ms 44256 KB Output is correct
47 Correct 33 ms 24404 KB Output is correct
48 Correct 384 ms 50668 KB Output is correct
49 Correct 391 ms 50616 KB Output is correct
50 Correct 373 ms 50488 KB Output is correct
51 Correct 371 ms 50504 KB Output is correct
52 Correct 383 ms 48616 KB Output is correct
53 Correct 308 ms 42824 KB Output is correct
54 Correct 379 ms 51384 KB Output is correct
55 Correct 390 ms 50616 KB Output is correct
56 Correct 283 ms 46496 KB Output is correct
57 Correct 385 ms 50620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20824 KB Output is correct
2 Correct 5 ms 20828 KB Output is correct
3 Correct 5 ms 20828 KB Output is correct
4 Correct 5 ms 20828 KB Output is correct
5 Correct 5 ms 20828 KB Output is correct
6 Correct 5 ms 21084 KB Output is correct
7 Correct 5 ms 21172 KB Output is correct
8 Correct 6 ms 21336 KB Output is correct
9 Correct 5 ms 20972 KB Output is correct
10 Correct 97 ms 40276 KB Output is correct
11 Correct 132 ms 44028 KB Output is correct
12 Correct 129 ms 43860 KB Output is correct
13 Correct 139 ms 45396 KB Output is correct
14 Correct 93 ms 41060 KB Output is correct
15 Correct 136 ms 40272 KB Output is correct
16 Correct 402 ms 49296 KB Output is correct
17 Correct 383 ms 48640 KB Output is correct
18 Correct 392 ms 50100 KB Output is correct
19 Correct 302 ms 45840 KB Output is correct
20 Correct 294 ms 44148 KB Output is correct
21 Correct 307 ms 46640 KB Output is correct
22 Correct 295 ms 46156 KB Output is correct
23 Correct 287 ms 46472 KB Output is correct
24 Correct 293 ms 46500 KB Output is correct
25 Correct 287 ms 45660 KB Output is correct
26 Correct 289 ms 46248 KB Output is correct
27 Correct 285 ms 45416 KB Output is correct
28 Correct 5 ms 21084 KB Output is correct
29 Correct 5 ms 21208 KB Output is correct
30 Correct 6 ms 21084 KB Output is correct
31 Correct 5 ms 20972 KB Output is correct
32 Correct 5 ms 21084 KB Output is correct
33 Correct 6 ms 21084 KB Output is correct
34 Correct 5 ms 21084 KB Output is correct
35 Correct 5 ms 21084 KB Output is correct
36 Correct 5 ms 21188 KB Output is correct
37 Correct 14 ms 24152 KB Output is correct
38 Correct 140 ms 45140 KB Output is correct
39 Correct 132 ms 45136 KB Output is correct
40 Correct 131 ms 45132 KB Output is correct
41 Correct 136 ms 44932 KB Output is correct
42 Correct 125 ms 44168 KB Output is correct
43 Correct 110 ms 41812 KB Output is correct
44 Correct 135 ms 45136 KB Output is correct
45 Correct 137 ms 45184 KB Output is correct
46 Correct 88 ms 42416 KB Output is correct
47 Correct 129 ms 44256 KB Output is correct
48 Correct 33 ms 24404 KB Output is correct
49 Correct 384 ms 50668 KB Output is correct
50 Correct 391 ms 50616 KB Output is correct
51 Correct 373 ms 50488 KB Output is correct
52 Correct 371 ms 50504 KB Output is correct
53 Correct 383 ms 48616 KB Output is correct
54 Correct 308 ms 42824 KB Output is correct
55 Correct 379 ms 51384 KB Output is correct
56 Correct 390 ms 50616 KB Output is correct
57 Correct 283 ms 46496 KB Output is correct
58 Correct 385 ms 50620 KB Output is correct
59 Correct 170 ms 30036 KB Output is correct
60 Correct 374 ms 50296 KB Output is correct
61 Correct 381 ms 49676 KB Output is correct
62 Correct 403 ms 51380 KB Output is correct
63 Correct 291 ms 47664 KB Output is correct
64 Correct 5 ms 21084 KB Output is correct
65 Correct 6 ms 20976 KB Output is correct
66 Correct 5 ms 21084 KB Output is correct
67 Correct 5 ms 21084 KB Output is correct
68 Correct 7 ms 20916 KB Output is correct
69 Correct 5 ms 21084 KB Output is correct
70 Correct 6 ms 21084 KB Output is correct
71 Correct 6 ms 21184 KB Output is correct
72 Correct 5 ms 21084 KB Output is correct
73 Correct 6 ms 21084 KB Output is correct
74 Correct 118 ms 43576 KB Output is correct
75 Correct 130 ms 45092 KB Output is correct
76 Correct 141 ms 44884 KB Output is correct
77 Correct 120 ms 44304 KB Output is correct
78 Correct 59 ms 32696 KB Output is correct
79 Correct 52 ms 29700 KB Output is correct
80 Correct 96 ms 39992 KB Output is correct
81 Correct 181 ms 49716 KB Output is correct
82 Correct 184 ms 51524 KB Output is correct
83 Correct 196 ms 52412 KB Output is correct
84 Correct 90 ms 41392 KB Output is correct
85 Correct 157 ms 48576 KB Output is correct
86 Correct 104 ms 30788 KB Output is correct
87 Correct 390 ms 50560 KB Output is correct
88 Correct 394 ms 50620 KB Output is correct
89 Correct 402 ms 47964 KB Output is correct
90 Correct 297 ms 38228 KB Output is correct
91 Correct 325 ms 39404 KB Output is correct
92 Correct 405 ms 45452 KB Output is correct
93 Correct 540 ms 55600 KB Output is correct
94 Correct 514 ms 57420 KB Output is correct
95 Correct 518 ms 57976 KB Output is correct
96 Correct 279 ms 47248 KB Output is correct
97 Correct 481 ms 52364 KB Output is correct