답안 #792887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792887 2023-07-25T10:33:02 Z Trisanu_Das 자매 도시 (APIO20_swap) C++17
100 / 100
146 ms 15156 KB
#include <bits/stdc++.h>
#include "swap.h"
using namespace std;
 
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, INT_MAX);
	ww2.assign(n, INT_MAX);
	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] != INT_MAX) 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 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 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 26 ms 5308 KB Output is correct
10 Correct 32 ms 6408 KB Output is correct
11 Correct 32 ms 6348 KB Output is correct
12 Correct 34 ms 6708 KB Output is correct
13 Correct 34 ms 6716 KB Output is correct
14 Correct 32 ms 5696 KB Output is correct
15 Correct 119 ms 10264 KB Output is correct
16 Correct 90 ms 10164 KB Output is correct
17 Correct 92 ms 10588 KB Output is correct
18 Correct 78 ms 10572 KB Output is correct
19 Correct 53 ms 6348 KB Output is correct
20 Correct 89 ms 10792 KB Output is correct
21 Correct 93 ms 11112 KB Output is correct
22 Correct 93 ms 11440 KB Output is correct
23 Correct 80 ms 11416 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 73 ms 10424 KB Output is correct
4 Correct 74 ms 10508 KB Output is correct
5 Correct 87 ms 10788 KB Output is correct
6 Correct 73 ms 10360 KB Output is correct
7 Correct 76 ms 10768 KB Output is correct
8 Correct 73 ms 10476 KB Output is correct
9 Correct 78 ms 10572 KB Output is correct
10 Correct 75 ms 10676 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 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 312 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 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 Correct 1 ms 340 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 312 KB Output is correct
20 Correct 1 ms 312 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 312 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 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 312 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 26 ms 5308 KB Output is correct
11 Correct 32 ms 6408 KB Output is correct
12 Correct 32 ms 6348 KB Output is correct
13 Correct 34 ms 6708 KB Output is correct
14 Correct 34 ms 6716 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 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 316 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 312 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 340 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 308 KB Output is correct
32 Correct 1 ms 312 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 5 ms 1108 KB Output is correct
35 Correct 32 ms 6444 KB Output is correct
36 Correct 32 ms 6316 KB Output is correct
37 Correct 32 ms 6336 KB Output is correct
38 Correct 32 ms 6352 KB Output is correct
39 Correct 32 ms 6220 KB Output is correct
40 Correct 29 ms 5704 KB Output is correct
41 Correct 34 ms 6692 KB Output is correct
42 Correct 32 ms 6348 KB Output is correct
43 Correct 34 ms 6452 KB Output is correct
44 Correct 38 ms 6708 KB Output is correct
45 Correct 61 ms 8552 KB Output is correct
46 Correct 32 ms 6348 KB Output is correct
47 Correct 31 ms 6332 KB Output is correct
48 Correct 37 ms 6848 KB Output is correct
49 Correct 50 ms 7400 KB Output is correct
50 Correct 39 ms 5944 KB Output is correct
51 Correct 45 ms 7536 KB Output is correct
52 Correct 57 ms 9620 KB Output is correct
53 Correct 77 ms 10452 KB Output is correct
54 Correct 71 ms 11204 KB Output is correct
55 Correct 31 ms 6432 KB Output is correct
56 Correct 60 ms 10120 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 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 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 26 ms 5308 KB Output is correct
10 Correct 32 ms 6408 KB Output is correct
11 Correct 32 ms 6348 KB Output is correct
12 Correct 34 ms 6708 KB Output is correct
13 Correct 34 ms 6716 KB Output is correct
14 Correct 32 ms 5696 KB Output is correct
15 Correct 119 ms 10264 KB Output is correct
16 Correct 90 ms 10164 KB Output is correct
17 Correct 92 ms 10588 KB Output is correct
18 Correct 78 ms 10572 KB Output is correct
19 Correct 73 ms 10424 KB Output is correct
20 Correct 74 ms 10508 KB Output is correct
21 Correct 87 ms 10788 KB Output is correct
22 Correct 73 ms 10360 KB Output is correct
23 Correct 76 ms 10768 KB Output is correct
24 Correct 73 ms 10476 KB Output is correct
25 Correct 78 ms 10572 KB Output is correct
26 Correct 75 ms 10676 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 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 316 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 5 ms 1108 KB Output is correct
37 Correct 32 ms 6444 KB Output is correct
38 Correct 32 ms 6316 KB Output is correct
39 Correct 32 ms 6336 KB Output is correct
40 Correct 32 ms 6352 KB Output is correct
41 Correct 32 ms 6220 KB Output is correct
42 Correct 29 ms 5704 KB Output is correct
43 Correct 34 ms 6692 KB Output is correct
44 Correct 32 ms 6348 KB Output is correct
45 Correct 34 ms 6452 KB Output is correct
46 Correct 38 ms 6708 KB Output is correct
47 Correct 10 ms 1620 KB Output is correct
48 Correct 93 ms 10420 KB Output is correct
49 Correct 95 ms 10516 KB Output is correct
50 Correct 89 ms 10508 KB Output is correct
51 Correct 89 ms 10428 KB Output is correct
52 Correct 86 ms 10180 KB Output is correct
53 Correct 79 ms 9820 KB Output is correct
54 Correct 92 ms 11408 KB Output is correct
55 Correct 94 ms 10520 KB Output is correct
56 Correct 78 ms 10508 KB Output is correct
57 Correct 91 ms 11420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 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 312 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 26 ms 5308 KB Output is correct
11 Correct 32 ms 6408 KB Output is correct
12 Correct 32 ms 6348 KB Output is correct
13 Correct 34 ms 6708 KB Output is correct
14 Correct 34 ms 6716 KB Output is correct
15 Correct 32 ms 5696 KB Output is correct
16 Correct 119 ms 10264 KB Output is correct
17 Correct 90 ms 10164 KB Output is correct
18 Correct 92 ms 10588 KB Output is correct
19 Correct 78 ms 10572 KB Output is correct
20 Correct 73 ms 10424 KB Output is correct
21 Correct 74 ms 10508 KB Output is correct
22 Correct 87 ms 10788 KB Output is correct
23 Correct 73 ms 10360 KB Output is correct
24 Correct 76 ms 10768 KB Output is correct
25 Correct 73 ms 10476 KB Output is correct
26 Correct 78 ms 10572 KB Output is correct
27 Correct 75 ms 10676 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 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 316 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 5 ms 1108 KB Output is correct
38 Correct 32 ms 6444 KB Output is correct
39 Correct 32 ms 6316 KB Output is correct
40 Correct 32 ms 6336 KB Output is correct
41 Correct 32 ms 6352 KB Output is correct
42 Correct 32 ms 6220 KB Output is correct
43 Correct 29 ms 5704 KB Output is correct
44 Correct 34 ms 6692 KB Output is correct
45 Correct 32 ms 6348 KB Output is correct
46 Correct 34 ms 6452 KB Output is correct
47 Correct 38 ms 6708 KB Output is correct
48 Correct 10 ms 1620 KB Output is correct
49 Correct 93 ms 10420 KB Output is correct
50 Correct 95 ms 10516 KB Output is correct
51 Correct 89 ms 10508 KB Output is correct
52 Correct 89 ms 10428 KB Output is correct
53 Correct 86 ms 10180 KB Output is correct
54 Correct 79 ms 9820 KB Output is correct
55 Correct 92 ms 11408 KB Output is correct
56 Correct 94 ms 10520 KB Output is correct
57 Correct 78 ms 10508 KB Output is correct
58 Correct 91 ms 11420 KB Output is correct
59 Correct 53 ms 6348 KB Output is correct
60 Correct 89 ms 10792 KB Output is correct
61 Correct 93 ms 11112 KB Output is correct
62 Correct 93 ms 11440 KB Output is correct
63 Correct 80 ms 11416 KB Output is correct
64 Correct 1 ms 312 KB Output is correct
65 Correct 1 ms 312 KB Output is correct
66 Correct 1 ms 340 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 1 ms 308 KB Output is correct
72 Correct 1 ms 312 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 61 ms 8552 KB Output is correct
75 Correct 32 ms 6348 KB Output is correct
76 Correct 31 ms 6332 KB Output is correct
77 Correct 37 ms 6848 KB Output is correct
78 Correct 50 ms 7400 KB Output is correct
79 Correct 39 ms 5944 KB Output is correct
80 Correct 45 ms 7536 KB Output is correct
81 Correct 57 ms 9620 KB Output is correct
82 Correct 77 ms 10452 KB Output is correct
83 Correct 71 ms 11204 KB Output is correct
84 Correct 31 ms 6432 KB Output is correct
85 Correct 60 ms 10120 KB Output is correct
86 Correct 30 ms 4080 KB Output is correct
87 Correct 93 ms 10540 KB Output is correct
88 Correct 89 ms 10416 KB Output is correct
89 Correct 85 ms 10552 KB Output is correct
90 Correct 115 ms 11112 KB Output is correct
91 Correct 100 ms 11220 KB Output is correct
92 Correct 101 ms 11692 KB Output is correct
93 Correct 115 ms 13388 KB Output is correct
94 Correct 113 ms 14284 KB Output is correct
95 Correct 146 ms 15156 KB Output is correct
96 Correct 85 ms 10636 KB Output is correct
97 Correct 108 ms 12536 KB Output is correct