Submission #684191

# Submission time Handle Problem Language Result Execution time Memory
684191 2023-01-20T15:49:55 Z thiago_bastos Swapping Cities (APIO20_swap) C++17
13 / 100
139 ms 12120 KB
#include "swap.h"

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 10;

int par[MAXN], depth[MAXN], t[MAXN], third[MAXN], deg[MAXN];

int findSet(int u) {
	return u == par[u] ? u : findSet(par[u]);
}

void merge(int u, int v, int w) {
	int a = findSet(u);
	int b = findSet(v);
	if(depth[a] > depth[b]) swap(a, b);
	++deg[u], ++deg[v];
	if(a == b) third[a] = min(third[a], w);
	else {
		par[a] = b;
		depth[b] += depth[a] == depth[b];
		int x = max(w, third[a]), y = max(w, third[b]);
		if(max(deg[u], deg[v]) > 2) x = min(x, w), y = min(y, w);	
		t[a] = w;
		third[b] = min(third[b], x);
		third[a] = min(third[a], y);
	}
}

void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {
	for(int i = 0; i < N; ++i) {
		par[i] = i;
		third[i] = INT_MAX;
	}
	vector<tuple<int, int, int>> edge(M);
	for(int i = 0; i < M; ++i) edge[i] = {W[i], U[i], V[i]};
	sort(edge.begin(), edge.end());
	for(auto [w, u, v] : edge) merge(u, v, w);
}

int h(int u) {
	return u == par[u] ? 0 : 1 + h(par[u]);
}

int getMinimumFuelCapacity(int X, int Y) {
	int hx = h(X), hy = h(Y);
	int ans = 0, trd = INT_MAX;
	while(hx != hy) {
		if(hx < hy) {
			swap(hx, hy);
			swap(X, Y);
		}
		--hx;
		trd = min(trd, third[X]);
		ans = max(ans, t[X]);
		X = par[X];
	}
	while(X != Y) {
		ans = max(ans, max(t[X], t[Y]));
		trd = min(trd, min(third[X], third[Y]));
		X = par[X];
		Y = par[Y];
	}	
	trd = min(trd, third[X]);
	while(X != par[X] && trd == INT_MAX) {
		ans = max(ans, t[X]);
		trd = min(trd, third[X]);
		X = par[X];
	}	
	ans = max(ans, min(trd, third[X]));
	return ans == INT_MAX ? -1 : ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 36 ms 6220 KB Output is correct
10 Correct 42 ms 7560 KB Output is correct
11 Correct 41 ms 7404 KB Output is correct
12 Correct 42 ms 7868 KB Output is correct
13 Correct 43 ms 7436 KB Output is correct
14 Correct 39 ms 6584 KB Output is correct
15 Correct 119 ms 11436 KB Output is correct
16 Correct 119 ms 11260 KB Output is correct
17 Correct 124 ms 11712 KB Output is correct
18 Correct 106 ms 11340 KB Output is correct
19 Correct 69 ms 6444 KB Output is correct
20 Correct 114 ms 11584 KB Output is correct
21 Correct 139 ms 11840 KB Output is correct
22 Correct 125 ms 12120 KB Output is correct
23 Correct 100 ms 11716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 87 ms 10840 KB Output is correct
4 Correct 104 ms 10908 KB Output is correct
5 Correct 93 ms 11272 KB Output is correct
6 Correct 93 ms 10784 KB Output is correct
7 Correct 97 ms 11184 KB Output is correct
8 Correct 93 ms 10800 KB Output is correct
9 Correct 90 ms 10948 KB Output is correct
10 Correct 90 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 324 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 396 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Incorrect 1 ms 320 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 36 ms 6220 KB Output is correct
11 Correct 42 ms 7560 KB Output is correct
12 Correct 41 ms 7404 KB Output is correct
13 Correct 42 ms 7868 KB Output is correct
14 Correct 43 ms 7436 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 396 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Incorrect 1 ms 320 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 36 ms 6220 KB Output is correct
10 Correct 42 ms 7560 KB Output is correct
11 Correct 41 ms 7404 KB Output is correct
12 Correct 42 ms 7868 KB Output is correct
13 Correct 43 ms 7436 KB Output is correct
14 Correct 39 ms 6584 KB Output is correct
15 Correct 119 ms 11436 KB Output is correct
16 Correct 119 ms 11260 KB Output is correct
17 Correct 124 ms 11712 KB Output is correct
18 Correct 106 ms 11340 KB Output is correct
19 Correct 87 ms 10840 KB Output is correct
20 Correct 104 ms 10908 KB Output is correct
21 Correct 93 ms 11272 KB Output is correct
22 Correct 93 ms 10784 KB Output is correct
23 Correct 97 ms 11184 KB Output is correct
24 Correct 93 ms 10800 KB Output is correct
25 Correct 90 ms 10948 KB Output is correct
26 Correct 90 ms 10840 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 6 ms 1224 KB Output is correct
37 Correct 39 ms 7532 KB Output is correct
38 Correct 41 ms 7584 KB Output is correct
39 Correct 43 ms 7524 KB Output is correct
40 Correct 44 ms 7516 KB Output is correct
41 Correct 39 ms 7472 KB Output is correct
42 Correct 35 ms 6860 KB Output is correct
43 Correct 42 ms 7860 KB Output is correct
44 Correct 40 ms 7488 KB Output is correct
45 Correct 40 ms 7484 KB Output is correct
46 Correct 44 ms 7816 KB Output is correct
47 Correct 12 ms 1600 KB Output is correct
48 Incorrect 123 ms 11396 KB Output isn't correct
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 36 ms 6220 KB Output is correct
11 Correct 42 ms 7560 KB Output is correct
12 Correct 41 ms 7404 KB Output is correct
13 Correct 42 ms 7868 KB Output is correct
14 Correct 43 ms 7436 KB Output is correct
15 Correct 39 ms 6584 KB Output is correct
16 Correct 119 ms 11436 KB Output is correct
17 Correct 119 ms 11260 KB Output is correct
18 Correct 124 ms 11712 KB Output is correct
19 Correct 106 ms 11340 KB Output is correct
20 Correct 87 ms 10840 KB Output is correct
21 Correct 104 ms 10908 KB Output is correct
22 Correct 93 ms 11272 KB Output is correct
23 Correct 93 ms 10784 KB Output is correct
24 Correct 97 ms 11184 KB Output is correct
25 Correct 93 ms 10800 KB Output is correct
26 Correct 90 ms 10948 KB Output is correct
27 Correct 90 ms 10840 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 324 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 6 ms 1224 KB Output is correct
38 Correct 39 ms 7532 KB Output is correct
39 Correct 41 ms 7584 KB Output is correct
40 Correct 43 ms 7524 KB Output is correct
41 Correct 44 ms 7516 KB Output is correct
42 Correct 39 ms 7472 KB Output is correct
43 Correct 35 ms 6860 KB Output is correct
44 Correct 42 ms 7860 KB Output is correct
45 Correct 40 ms 7488 KB Output is correct
46 Correct 40 ms 7484 KB Output is correct
47 Correct 44 ms 7816 KB Output is correct
48 Correct 12 ms 1600 KB Output is correct
49 Incorrect 123 ms 11396 KB Output isn't correct
50 Halted 0 ms 0 KB -