답안 #535992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535992 2022-03-12T03:29:51 Z lunchbox 자매 도시 (APIO20_swap) C++17
6 / 100
117 ms 6976 KB
#include <bits/stdc++.h>
#include "swap.h"
using namespace std;

#define N	100000
#define INF	0x3f3f3f3f

int ds[N], ww1[N], ww2[N];

int find(int i) {
	return ds[i] < 0 ? i : find(ds[i]);
}

void join(int i, int j, int w) {
	i = find(i), j = find(j);
	if (i == j)
		ww2[i] = min(ww2[i], w);
	else {
		if (ds[i] > ds[j])
			swap(i, j);
		ds[i] += ds[j], ds[j] = i;
		ww1[j] = w;
		ww2[i] = min(ww2[i], ww2[j]);
	}
}

void init(int n, int m, std::vector<int> ii, std::vector<int> jj, std::vector<int> ww) {
	vector<int> hh(m);
	for (int i = 0; i < m; i++)
		hh[i] = i;
	sort(hh.begin(), hh.end(), [&](int i, int j) {
		return ww[i] < ww[j];
	});
	memset(ds, -1, n * sizeof *ds);
	memset(ww1, 0x3f, n * sizeof *ww1);
	memset(ww2, 0x3f, n * sizeof *ww2);
	for (int h : hh)
		join(ii[h], jj[h], ww[h]);
}

int getMinimumFuelCapacity(int i, int j) {
	int w1 = -1;

	while (i != j && (ds[i] >= 0 || ds[j] >= 0)) {
		if (ww1[i] < ww1[j]) {
			w1 = ww1[i];
			i = ds[i];
		} else {
			w1 = ww1[j];
			j = ds[j];
		}
	}
	while (i >= 0) {
		if (ww2[i] != INF)
			return max(w1, ww2[i]);
		w1 = ww1[i];
		i = ds[i];
	}
	return -1;
}

/*
int main() {
	int _N, _M;
	cin >> _N >> _M;
	vector<int> _U(_M), _V(_M), _W(_M);
	for (int i = 0; i < _M; i++)
		cin >> _U[i] >> _V[i] >> _W[i];
	init(_N, _M, _U, _V, _W);

	int _Q;
	cin >> _Q;
	while (_Q--) {
		int _u, _v;
		cin >> _u >> _v;
		cout << getMinimumFuelCapacity(_u, _v) << '\n';
	}
}
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 36 ms 3356 KB Output is correct
10 Correct 57 ms 3960 KB Output is correct
11 Correct 40 ms 3968 KB Output is correct
12 Correct 43 ms 4108 KB Output is correct
13 Correct 43 ms 4172 KB Output is correct
14 Correct 43 ms 3404 KB Output is correct
15 Correct 116 ms 5584 KB Output is correct
16 Correct 116 ms 5508 KB Output is correct
17 Correct 117 ms 5708 KB Output is correct
18 Correct 96 ms 5728 KB Output is correct
19 Correct 59 ms 4188 KB Output is correct
20 Correct 111 ms 6616 KB Output is correct
21 Correct 110 ms 6808 KB Output is correct
22 Correct 111 ms 6976 KB Output is correct
23 Correct 103 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 94 ms 5452 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 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 3356 KB Output is correct
11 Correct 57 ms 3960 KB Output is correct
12 Correct 40 ms 3968 KB Output is correct
13 Correct 43 ms 4108 KB Output is correct
14 Correct 43 ms 4172 KB Output is correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 36 ms 3356 KB Output is correct
10 Correct 57 ms 3960 KB Output is correct
11 Correct 40 ms 3968 KB Output is correct
12 Correct 43 ms 4108 KB Output is correct
13 Correct 43 ms 4172 KB Output is correct
14 Correct 43 ms 3404 KB Output is correct
15 Correct 116 ms 5584 KB Output is correct
16 Correct 116 ms 5508 KB Output is correct
17 Correct 117 ms 5708 KB Output is correct
18 Correct 96 ms 5728 KB Output is correct
19 Incorrect 94 ms 5452 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 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 3356 KB Output is correct
11 Correct 57 ms 3960 KB Output is correct
12 Correct 40 ms 3968 KB Output is correct
13 Correct 43 ms 4108 KB Output is correct
14 Correct 43 ms 4172 KB Output is correct
15 Correct 43 ms 3404 KB Output is correct
16 Correct 116 ms 5584 KB Output is correct
17 Correct 116 ms 5508 KB Output is correct
18 Correct 117 ms 5708 KB Output is correct
19 Correct 96 ms 5728 KB Output is correct
20 Incorrect 94 ms 5452 KB Output isn't correct
21 Halted 0 ms 0 KB -