답안 #536143

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536143 2022-03-12T13:23:02 Z lunchbox 자매 도시 (APIO20_swap) C++17
100 / 100
185 ms 15040 KB
#include <bits/stdc++.h>
#include "swap.h"
using namespace std;
 
const int INF = 0x3f3f3f3f;
 
vector<int> ds, ww1, ww2;
 
int find(int i) {
	return ds[i] < 0 ? i : find(ds[i]);
}
 
void join(int i, int j, int w, int bridge) {
	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], max(w, bridge ? 0 : ww2[j]));
	}
}
 
void init(int n, int m, std::vector<int> ii, std::vector<int> jj, std::vector<int> ww) {
	vector<int> hh(m), dd(n);
	for (int i = 0; i < m; i++)
		hh[i] = i;
	sort(hh.begin(), hh.end(), [&](int i, int j) {
		return ww[i] < ww[j];
	});
	ds.assign(n, -1);
	ww1.assign(n, INF);
	ww2.assign(n, INF);
	for (int h : hh) {
		dd[ii[h]]++, dd[jj[h]]++;
		join(ii[h], jj[h], ww[h], dd[ii[h]] >= 3 || dd[jj[h]] >= 3);
	}
}
 
int getMinimumFuelCapacity(int i, int j) {
	int w = -1;
 
	while (i != j) {
		if (ww1[i] < ww1[j]) {
			w = ww1[i];
			i = ds[i];
		} else {
			w = ww1[j];
			j = ds[j];
		}
	}
	while (i >= 0) {
		if (ww2[i] != INF)
			return max(w, ww2[i]);
		w = ww1[i];
		i = ds[i];
	}
	return -1;
}
# 결과 실행 시간 메모리 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 308 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 304 KB Output is correct
9 Correct 39 ms 5308 KB Output is correct
10 Correct 46 ms 6408 KB Output is correct
11 Correct 62 ms 6380 KB Output is correct
12 Correct 51 ms 6696 KB Output is correct
13 Correct 46 ms 6680 KB Output is correct
14 Correct 43 ms 5580 KB Output is correct
15 Correct 129 ms 10316 KB Output is correct
16 Correct 121 ms 10088 KB Output is correct
17 Correct 121 ms 10572 KB Output is correct
18 Correct 112 ms 10684 KB Output is correct
19 Correct 67 ms 6336 KB Output is correct
20 Correct 121 ms 10768 KB Output is correct
21 Correct 129 ms 11068 KB Output is correct
22 Correct 122 ms 11396 KB Output is correct
23 Correct 116 ms 11424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 96 ms 10412 KB Output is correct
4 Correct 104 ms 10488 KB Output is correct
5 Correct 103 ms 10796 KB Output is correct
6 Correct 102 ms 10392 KB Output is correct
7 Correct 105 ms 10772 KB Output is correct
8 Correct 97 ms 10524 KB Output is correct
9 Correct 126 ms 10592 KB Output is correct
10 Correct 101 ms 10532 KB Output is correct
# 결과 실행 시간 메모리 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 308 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 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 316 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 332 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 308 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 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 212 KB Output is correct
6 Correct 1 ms 308 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 304 KB Output is correct
10 Correct 39 ms 5308 KB Output is correct
11 Correct 46 ms 6408 KB Output is correct
12 Correct 62 ms 6380 KB Output is correct
13 Correct 51 ms 6696 KB Output is correct
14 Correct 46 ms 6680 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
16 Correct 1 ms 316 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 332 KB Output is correct
21 Correct 1 ms 340 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 Correct 1 ms 308 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 2 ms 340 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 7 ms 1108 KB Output is correct
35 Correct 46 ms 6432 KB Output is correct
36 Correct 45 ms 6312 KB Output is correct
37 Correct 44 ms 6316 KB Output is correct
38 Correct 44 ms 6300 KB Output is correct
39 Correct 45 ms 6428 KB Output is correct
40 Correct 56 ms 5804 KB Output is correct
41 Correct 49 ms 6704 KB Output is correct
42 Correct 46 ms 6316 KB Output is correct
43 Correct 42 ms 6324 KB Output is correct
44 Correct 46 ms 6604 KB Output is correct
45 Correct 73 ms 8632 KB Output is correct
46 Correct 43 ms 6320 KB Output is correct
47 Correct 48 ms 6316 KB Output is correct
48 Correct 56 ms 6852 KB Output is correct
49 Correct 66 ms 7384 KB Output is correct
50 Correct 53 ms 5928 KB Output is correct
51 Correct 64 ms 7416 KB Output is correct
52 Correct 89 ms 9600 KB Output is correct
53 Correct 94 ms 10444 KB Output is correct
54 Correct 96 ms 11204 KB Output is correct
55 Correct 43 ms 6432 KB Output is correct
56 Correct 98 ms 10208 KB Output is correct
# 결과 실행 시간 메모리 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 308 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 304 KB Output is correct
9 Correct 39 ms 5308 KB Output is correct
10 Correct 46 ms 6408 KB Output is correct
11 Correct 62 ms 6380 KB Output is correct
12 Correct 51 ms 6696 KB Output is correct
13 Correct 46 ms 6680 KB Output is correct
14 Correct 43 ms 5580 KB Output is correct
15 Correct 129 ms 10316 KB Output is correct
16 Correct 121 ms 10088 KB Output is correct
17 Correct 121 ms 10572 KB Output is correct
18 Correct 112 ms 10684 KB Output is correct
19 Correct 96 ms 10412 KB Output is correct
20 Correct 104 ms 10488 KB Output is correct
21 Correct 103 ms 10796 KB Output is correct
22 Correct 102 ms 10392 KB Output is correct
23 Correct 105 ms 10772 KB Output is correct
24 Correct 97 ms 10524 KB Output is correct
25 Correct 126 ms 10592 KB Output is correct
26 Correct 101 ms 10532 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 316 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 332 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 340 KB Output is correct
36 Correct 7 ms 1108 KB Output is correct
37 Correct 46 ms 6432 KB Output is correct
38 Correct 45 ms 6312 KB Output is correct
39 Correct 44 ms 6316 KB Output is correct
40 Correct 44 ms 6300 KB Output is correct
41 Correct 45 ms 6428 KB Output is correct
42 Correct 56 ms 5804 KB Output is correct
43 Correct 49 ms 6704 KB Output is correct
44 Correct 46 ms 6316 KB Output is correct
45 Correct 42 ms 6324 KB Output is correct
46 Correct 46 ms 6604 KB Output is correct
47 Correct 16 ms 1576 KB Output is correct
48 Correct 121 ms 10532 KB Output is correct
49 Correct 122 ms 10516 KB Output is correct
50 Correct 128 ms 10532 KB Output is correct
51 Correct 115 ms 10496 KB Output is correct
52 Correct 110 ms 10196 KB Output is correct
53 Correct 129 ms 9884 KB Output is correct
54 Correct 126 ms 11436 KB Output is correct
55 Correct 130 ms 10404 KB Output is correct
56 Correct 102 ms 10532 KB Output is correct
57 Correct 120 ms 11428 KB Output is correct
# 결과 실행 시간 메모리 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 212 KB Output is correct
6 Correct 1 ms 308 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 304 KB Output is correct
10 Correct 39 ms 5308 KB Output is correct
11 Correct 46 ms 6408 KB Output is correct
12 Correct 62 ms 6380 KB Output is correct
13 Correct 51 ms 6696 KB Output is correct
14 Correct 46 ms 6680 KB Output is correct
15 Correct 43 ms 5580 KB Output is correct
16 Correct 129 ms 10316 KB Output is correct
17 Correct 121 ms 10088 KB Output is correct
18 Correct 121 ms 10572 KB Output is correct
19 Correct 112 ms 10684 KB Output is correct
20 Correct 96 ms 10412 KB Output is correct
21 Correct 104 ms 10488 KB Output is correct
22 Correct 103 ms 10796 KB Output is correct
23 Correct 102 ms 10392 KB Output is correct
24 Correct 105 ms 10772 KB Output is correct
25 Correct 97 ms 10524 KB Output is correct
26 Correct 126 ms 10592 KB Output is correct
27 Correct 101 ms 10532 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 316 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 332 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 7 ms 1108 KB Output is correct
38 Correct 46 ms 6432 KB Output is correct
39 Correct 45 ms 6312 KB Output is correct
40 Correct 44 ms 6316 KB Output is correct
41 Correct 44 ms 6300 KB Output is correct
42 Correct 45 ms 6428 KB Output is correct
43 Correct 56 ms 5804 KB Output is correct
44 Correct 49 ms 6704 KB Output is correct
45 Correct 46 ms 6316 KB Output is correct
46 Correct 42 ms 6324 KB Output is correct
47 Correct 46 ms 6604 KB Output is correct
48 Correct 16 ms 1576 KB Output is correct
49 Correct 121 ms 10532 KB Output is correct
50 Correct 122 ms 10516 KB Output is correct
51 Correct 128 ms 10532 KB Output is correct
52 Correct 115 ms 10496 KB Output is correct
53 Correct 110 ms 10196 KB Output is correct
54 Correct 129 ms 9884 KB Output is correct
55 Correct 126 ms 11436 KB Output is correct
56 Correct 130 ms 10404 KB Output is correct
57 Correct 102 ms 10532 KB Output is correct
58 Correct 120 ms 11428 KB Output is correct
59 Correct 67 ms 6336 KB Output is correct
60 Correct 121 ms 10768 KB Output is correct
61 Correct 129 ms 11068 KB Output is correct
62 Correct 122 ms 11396 KB Output is correct
63 Correct 116 ms 11424 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 308 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 2 ms 340 KB Output is correct
72 Correct 1 ms 308 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 73 ms 8632 KB Output is correct
75 Correct 43 ms 6320 KB Output is correct
76 Correct 48 ms 6316 KB Output is correct
77 Correct 56 ms 6852 KB Output is correct
78 Correct 66 ms 7384 KB Output is correct
79 Correct 53 ms 5928 KB Output is correct
80 Correct 64 ms 7416 KB Output is correct
81 Correct 89 ms 9600 KB Output is correct
82 Correct 94 ms 10444 KB Output is correct
83 Correct 96 ms 11204 KB Output is correct
84 Correct 43 ms 6432 KB Output is correct
85 Correct 98 ms 10208 KB Output is correct
86 Correct 39 ms 4076 KB Output is correct
87 Correct 119 ms 10504 KB Output is correct
88 Correct 123 ms 10536 KB Output is correct
89 Correct 119 ms 10596 KB Output is correct
90 Correct 137 ms 11188 KB Output is correct
91 Correct 139 ms 11216 KB Output is correct
92 Correct 144 ms 11772 KB Output is correct
93 Correct 147 ms 13360 KB Output is correct
94 Correct 164 ms 14332 KB Output is correct
95 Correct 185 ms 15040 KB Output is correct
96 Correct 105 ms 10580 KB Output is correct
97 Correct 134 ms 12536 KB Output is correct