답안 #684015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684015 2023-01-20T03:47:10 Z thiago_bastos 자매 도시 (APIO20_swap) C++17
13 / 100
124 ms 12180 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]);
}

int h(int u) {
	return u == par[u] ? 0 : 1 + h(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 getMinimumFuelCapacity(int X, int Y) {
	int Z = findSet(X);
	int hx = h(X), hy = h(Y), ans = 0, trd = INT_MAX;
	while(hx != hy) {
		if(hx < hy) {
			swap(hx, hy);
			swap(X, Y);	
		}
		--hx;
		ans = max(ans, t[X]);
		trd = min(trd, third[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 = min(trd, third[X]);
		X = par[X];
	}
	ans = max(ans, min(third[X], trd));
	return ans == INT_MAX ? -1 : ans;
}

Compilation message

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:48:6: warning: unused variable 'Z' [-Wunused-variable]
   48 |  int Z = findSet(X);
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 320 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 33 ms 6216 KB Output is correct
10 Correct 39 ms 7560 KB Output is correct
11 Correct 39 ms 7416 KB Output is correct
12 Correct 42 ms 7784 KB Output is correct
13 Correct 38 ms 7492 KB Output is correct
14 Correct 38 ms 6604 KB Output is correct
15 Correct 120 ms 11432 KB Output is correct
16 Correct 121 ms 11272 KB Output is correct
17 Correct 124 ms 11724 KB Output is correct
18 Correct 92 ms 11368 KB Output is correct
19 Correct 60 ms 6360 KB Output is correct
20 Correct 112 ms 11636 KB Output is correct
21 Correct 124 ms 11816 KB Output is correct
22 Correct 115 ms 12180 KB Output is correct
23 Correct 100 ms 11812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 113 ms 10772 KB Output is correct
4 Correct 87 ms 10772 KB Output is correct
5 Correct 93 ms 11200 KB Output is correct
6 Correct 92 ms 10720 KB Output is correct
7 Correct 93 ms 11156 KB Output is correct
8 Correct 87 ms 10796 KB Output is correct
9 Correct 86 ms 10916 KB Output is correct
10 Correct 90 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 320 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 320 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 328 KB Output is correct
15 Incorrect 1 ms 324 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 320 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 33 ms 6216 KB Output is correct
11 Correct 39 ms 7560 KB Output is correct
12 Correct 39 ms 7416 KB Output is correct
13 Correct 42 ms 7784 KB Output is correct
14 Correct 38 ms 7492 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 320 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 328 KB Output is correct
20 Incorrect 1 ms 324 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 320 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 33 ms 6216 KB Output is correct
10 Correct 39 ms 7560 KB Output is correct
11 Correct 39 ms 7416 KB Output is correct
12 Correct 42 ms 7784 KB Output is correct
13 Correct 38 ms 7492 KB Output is correct
14 Correct 38 ms 6604 KB Output is correct
15 Correct 120 ms 11432 KB Output is correct
16 Correct 121 ms 11272 KB Output is correct
17 Correct 124 ms 11724 KB Output is correct
18 Correct 92 ms 11368 KB Output is correct
19 Correct 113 ms 10772 KB Output is correct
20 Correct 87 ms 10772 KB Output is correct
21 Correct 93 ms 11200 KB Output is correct
22 Correct 92 ms 10720 KB Output is correct
23 Correct 93 ms 11156 KB Output is correct
24 Correct 87 ms 10796 KB Output is correct
25 Correct 86 ms 10916 KB Output is correct
26 Correct 90 ms 10844 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 320 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 328 KB Output is correct
32 Incorrect 1 ms 324 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 320 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 33 ms 6216 KB Output is correct
11 Correct 39 ms 7560 KB Output is correct
12 Correct 39 ms 7416 KB Output is correct
13 Correct 42 ms 7784 KB Output is correct
14 Correct 38 ms 7492 KB Output is correct
15 Correct 38 ms 6604 KB Output is correct
16 Correct 120 ms 11432 KB Output is correct
17 Correct 121 ms 11272 KB Output is correct
18 Correct 124 ms 11724 KB Output is correct
19 Correct 92 ms 11368 KB Output is correct
20 Correct 113 ms 10772 KB Output is correct
21 Correct 87 ms 10772 KB Output is correct
22 Correct 93 ms 11200 KB Output is correct
23 Correct 92 ms 10720 KB Output is correct
24 Correct 93 ms 11156 KB Output is correct
25 Correct 87 ms 10796 KB Output is correct
26 Correct 86 ms 10916 KB Output is correct
27 Correct 90 ms 10844 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 320 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 328 KB Output is correct
33 Incorrect 1 ms 324 KB Output isn't correct
34 Halted 0 ms 0 KB -