답안 #535988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535988 2022-03-12T03:20:04 Z lunchbox 자매 도시 (APIO20_swap) C++17
0 / 100
145 ms 5732 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];
		}
	}
	w1 = max(w1, ww2[i]);
	return w1 == INF ? -1 : w1;
}

/*
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 34 ms 3380 KB Output is correct
10 Correct 42 ms 4044 KB Output is correct
11 Correct 42 ms 3916 KB Output is correct
12 Correct 45 ms 4208 KB Output is correct
13 Correct 50 ms 4168 KB Output is correct
14 Correct 42 ms 3500 KB Output is correct
15 Correct 113 ms 5680 KB Output is correct
16 Correct 118 ms 5452 KB Output is correct
17 Correct 145 ms 5732 KB Output is correct
18 Correct 97 ms 5732 KB Output is correct
19 Incorrect 63 ms 4236 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 Incorrect 95 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 34 ms 3380 KB Output is correct
11 Correct 42 ms 4044 KB Output is correct
12 Correct 42 ms 3916 KB Output is correct
13 Correct 45 ms 4208 KB Output is correct
14 Correct 50 ms 4168 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 34 ms 3380 KB Output is correct
10 Correct 42 ms 4044 KB Output is correct
11 Correct 42 ms 3916 KB Output is correct
12 Correct 45 ms 4208 KB Output is correct
13 Correct 50 ms 4168 KB Output is correct
14 Correct 42 ms 3500 KB Output is correct
15 Correct 113 ms 5680 KB Output is correct
16 Correct 118 ms 5452 KB Output is correct
17 Correct 145 ms 5732 KB Output is correct
18 Correct 97 ms 5732 KB Output is correct
19 Incorrect 95 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 34 ms 3380 KB Output is correct
11 Correct 42 ms 4044 KB Output is correct
12 Correct 42 ms 3916 KB Output is correct
13 Correct 45 ms 4208 KB Output is correct
14 Correct 50 ms 4168 KB Output is correct
15 Correct 42 ms 3500 KB Output is correct
16 Correct 113 ms 5680 KB Output is correct
17 Correct 118 ms 5452 KB Output is correct
18 Correct 145 ms 5732 KB Output is correct
19 Correct 97 ms 5732 KB Output is correct
20 Incorrect 95 ms 5452 KB Output isn't correct
21 Halted 0 ms 0 KB -