Submission #684020

# Submission time Handle Problem Language Result Execution time Memory
684020 2023-01-20T04:04:17 Z thiago_bastos Swapping Cities (APIO20_swap) C++17
13 / 100
126 ms 8096 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];
	}	
	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 1 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 324 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 34 ms 4928 KB Output is correct
10 Correct 44 ms 5908 KB Output is correct
11 Correct 50 ms 5768 KB Output is correct
12 Correct 40 ms 6148 KB Output is correct
13 Correct 41 ms 5756 KB Output is correct
14 Correct 39 ms 5064 KB Output is correct
15 Correct 123 ms 7456 KB Output is correct
16 Correct 123 ms 7304 KB Output is correct
17 Correct 118 ms 7624 KB Output is correct
18 Correct 95 ms 7236 KB Output is correct
19 Correct 70 ms 4752 KB Output is correct
20 Correct 112 ms 7780 KB Output is correct
21 Correct 119 ms 7876 KB Output is correct
22 Correct 126 ms 8096 KB Output is correct
23 Correct 104 ms 7844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 105 ms 7368 KB Output is correct
4 Correct 93 ms 7484 KB Output is correct
5 Correct 100 ms 7676 KB Output is correct
6 Correct 91 ms 7356 KB Output is correct
7 Correct 92 ms 7596 KB Output is correct
8 Correct 102 ms 7460 KB Output is correct
9 Correct 113 ms 7504 KB Output is correct
10 Correct 93 ms 7396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 324 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 1 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 Incorrect 1 ms 340 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 324 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 34 ms 4928 KB Output is correct
11 Correct 44 ms 5908 KB Output is correct
12 Correct 50 ms 5768 KB Output is correct
13 Correct 40 ms 6148 KB Output is correct
14 Correct 41 ms 5756 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 Incorrect 1 ms 340 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 324 KB Output is correct
8 Correct 2 ms 336 KB Output is correct
9 Correct 34 ms 4928 KB Output is correct
10 Correct 44 ms 5908 KB Output is correct
11 Correct 50 ms 5768 KB Output is correct
12 Correct 40 ms 6148 KB Output is correct
13 Correct 41 ms 5756 KB Output is correct
14 Correct 39 ms 5064 KB Output is correct
15 Correct 123 ms 7456 KB Output is correct
16 Correct 123 ms 7304 KB Output is correct
17 Correct 118 ms 7624 KB Output is correct
18 Correct 95 ms 7236 KB Output is correct
19 Correct 105 ms 7368 KB Output is correct
20 Correct 93 ms 7484 KB Output is correct
21 Correct 100 ms 7676 KB Output is correct
22 Correct 91 ms 7356 KB Output is correct
23 Correct 92 ms 7596 KB Output is correct
24 Correct 102 ms 7460 KB Output is correct
25 Correct 113 ms 7504 KB Output is correct
26 Correct 93 ms 7396 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 Incorrect 1 ms 340 KB Output isn't correct
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 324 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 34 ms 4928 KB Output is correct
11 Correct 44 ms 5908 KB Output is correct
12 Correct 50 ms 5768 KB Output is correct
13 Correct 40 ms 6148 KB Output is correct
14 Correct 41 ms 5756 KB Output is correct
15 Correct 39 ms 5064 KB Output is correct
16 Correct 123 ms 7456 KB Output is correct
17 Correct 123 ms 7304 KB Output is correct
18 Correct 118 ms 7624 KB Output is correct
19 Correct 95 ms 7236 KB Output is correct
20 Correct 105 ms 7368 KB Output is correct
21 Correct 93 ms 7484 KB Output is correct
22 Correct 100 ms 7676 KB Output is correct
23 Correct 91 ms 7356 KB Output is correct
24 Correct 92 ms 7596 KB Output is correct
25 Correct 102 ms 7460 KB Output is correct
26 Correct 113 ms 7504 KB Output is correct
27 Correct 93 ms 7396 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 Incorrect 1 ms 340 KB Output isn't correct
34 Halted 0 ms 0 KB -