답안 #401898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
401898 2021-05-11T00:52:02 Z faresbasbs 자매 도시 (APIO20_swap) C++14
100 / 100
490 ms 44452 KB
#include <bits/stdc++.h>
#include "swap.h"
using namespace std;
vector<pair<int,pair<int,int>>> edges;
set<pair<int,int>> pars[100001];
int par[100001],deg[100001];
vector<int> group[100001];
bool good[100001];

int find(int curr){
	return curr == par[curr] ? curr : par[curr] = find(par[curr]);
}

void merge(int a , int b , int c){
	int p1 = find(a) , p2 = find(b);
	if((good[p2] && !good[p1]) || group[p1].size() < group[p2].size()){
		swap(a,b),swap(p1,p2);
	}
	int pre = good[p1];
	if(good[p1] || good[p2] || deg[a] > 1 || deg[b] > 1){
		good[p1] = 1;
	}
	if(pre == 0 && good[p1]){
		for(auto i : group[p1]){
			pars[i].insert({c,p1});
		}
	}
	deg[a] += 1 , deg[b] += 1;
	for(auto i : group[p2]){
		if(good[p1]){
			pars[i].insert({c,p1});
		}
		group[p1].push_back(i);
		par[i] = p1;
	}
	group[p2].clear();
}

void init(int N , int M , vector<int> U , vector<int> V , vector<int> W){
	for(int i = 0 ; i < N ; i += 1){
		par[i] = i;
		pars[i].insert({0,i});
		group[i] = {i};
	}
	for(int i = 0 ; i < M ; i += 1){
		edges.push_back({W[i],{U[i],V[i]}});
	}
	sort(edges.begin(),edges.end());
	for(auto i : edges){
		int a = i.second.first , b = i.second.second , c = i.first;
		if(find(a) == find(b)){
			if(!good[find(a)]){
				good[find(a)] = 1;
				for(auto j : group[find(a)]){
					pars[j].insert({c,find(a)});
				}
			}
			continue;
		}
		merge(a,b,c);
	}
}

int getMinimumFuelCapacity(int X , int Y){
	for(auto i : pars[X]){
		for(auto j : pars[Y]){
			if(i.second == j.second){
				return max(i.first,j.first);
			}
		}
	}
	return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7500 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 6 ms 7496 KB Output is correct
8 Correct 6 ms 7492 KB Output is correct
9 Correct 78 ms 21932 KB Output is correct
10 Correct 96 ms 24568 KB Output is correct
11 Correct 92 ms 24492 KB Output is correct
12 Correct 98 ms 25380 KB Output is correct
13 Correct 82 ms 22716 KB Output is correct
14 Correct 89 ms 22072 KB Output is correct
15 Correct 179 ms 27032 KB Output is correct
16 Correct 170 ms 26268 KB Output is correct
17 Correct 184 ms 27416 KB Output is correct
18 Correct 165 ms 24384 KB Output is correct
19 Correct 80 ms 15860 KB Output is correct
20 Correct 232 ms 31640 KB Output is correct
21 Correct 230 ms 31088 KB Output is correct
22 Correct 248 ms 32448 KB Output is correct
23 Correct 228 ms 29984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 210 ms 28624 KB Output is correct
4 Correct 217 ms 29440 KB Output is correct
5 Correct 224 ms 29124 KB Output is correct
6 Correct 215 ms 29348 KB Output is correct
7 Correct 221 ms 29256 KB Output is correct
8 Correct 215 ms 28532 KB Output is correct
9 Correct 216 ms 29064 KB Output is correct
10 Correct 209 ms 28528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7500 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 6 ms 7496 KB Output is correct
8 Correct 6 ms 7492 KB Output is correct
9 Correct 4 ms 7236 KB Output is correct
10 Correct 6 ms 7488 KB Output is correct
11 Correct 6 ms 7488 KB Output is correct
12 Correct 6 ms 7484 KB Output is correct
13 Correct 6 ms 7584 KB Output is correct
14 Correct 6 ms 7500 KB Output is correct
15 Correct 5 ms 7500 KB Output is correct
16 Correct 6 ms 7500 KB Output is correct
17 Correct 6 ms 7484 KB Output is correct
18 Correct 6 ms 7636 KB Output is correct
19 Correct 5 ms 7500 KB Output is correct
20 Correct 6 ms 7500 KB Output is correct
21 Correct 6 ms 7624 KB Output is correct
22 Correct 5 ms 7372 KB Output is correct
23 Correct 6 ms 7500 KB Output is correct
24 Correct 7 ms 7620 KB Output is correct
25 Correct 6 ms 7628 KB Output is correct
26 Correct 6 ms 7500 KB Output is correct
27 Correct 6 ms 7500 KB Output is correct
28 Correct 6 ms 7628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7236 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7500 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 6 ms 7496 KB Output is correct
9 Correct 6 ms 7492 KB Output is correct
10 Correct 78 ms 21932 KB Output is correct
11 Correct 96 ms 24568 KB Output is correct
12 Correct 92 ms 24492 KB Output is correct
13 Correct 98 ms 25380 KB Output is correct
14 Correct 82 ms 22716 KB Output is correct
15 Correct 6 ms 7488 KB Output is correct
16 Correct 6 ms 7488 KB Output is correct
17 Correct 6 ms 7484 KB Output is correct
18 Correct 6 ms 7584 KB Output is correct
19 Correct 6 ms 7500 KB Output is correct
20 Correct 5 ms 7500 KB Output is correct
21 Correct 6 ms 7500 KB Output is correct
22 Correct 6 ms 7484 KB Output is correct
23 Correct 6 ms 7636 KB Output is correct
24 Correct 5 ms 7500 KB Output is correct
25 Correct 6 ms 7500 KB Output is correct
26 Correct 6 ms 7624 KB Output is correct
27 Correct 5 ms 7372 KB Output is correct
28 Correct 6 ms 7500 KB Output is correct
29 Correct 7 ms 7620 KB Output is correct
30 Correct 6 ms 7628 KB Output is correct
31 Correct 6 ms 7500 KB Output is correct
32 Correct 6 ms 7500 KB Output is correct
33 Correct 6 ms 7628 KB Output is correct
34 Correct 21 ms 11608 KB Output is correct
35 Correct 139 ms 30384 KB Output is correct
36 Correct 156 ms 32508 KB Output is correct
37 Correct 185 ms 36164 KB Output is correct
38 Correct 202 ms 37360 KB Output is correct
39 Correct 239 ms 40632 KB Output is correct
40 Correct 218 ms 38348 KB Output is correct
41 Correct 152 ms 31164 KB Output is correct
42 Correct 124 ms 29072 KB Output is correct
43 Correct 116 ms 27960 KB Output is correct
44 Correct 263 ms 42256 KB Output is correct
45 Correct 152 ms 28848 KB Output is correct
46 Correct 150 ms 31544 KB Output is correct
47 Correct 155 ms 31144 KB Output is correct
48 Correct 147 ms 29624 KB Output is correct
49 Correct 73 ms 16352 KB Output is correct
50 Correct 61 ms 14908 KB Output is correct
51 Correct 124 ms 25480 KB Output is correct
52 Correct 178 ms 34120 KB Output is correct
53 Correct 254 ms 39736 KB Output is correct
54 Correct 172 ms 32824 KB Output is correct
55 Correct 120 ms 28348 KB Output is correct
56 Correct 189 ms 33916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7244 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7372 KB Output is correct
5 Correct 5 ms 7500 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 6 ms 7496 KB Output is correct
8 Correct 6 ms 7492 KB Output is correct
9 Correct 78 ms 21932 KB Output is correct
10 Correct 96 ms 24568 KB Output is correct
11 Correct 92 ms 24492 KB Output is correct
12 Correct 98 ms 25380 KB Output is correct
13 Correct 82 ms 22716 KB Output is correct
14 Correct 89 ms 22072 KB Output is correct
15 Correct 179 ms 27032 KB Output is correct
16 Correct 170 ms 26268 KB Output is correct
17 Correct 184 ms 27416 KB Output is correct
18 Correct 165 ms 24384 KB Output is correct
19 Correct 210 ms 28624 KB Output is correct
20 Correct 217 ms 29440 KB Output is correct
21 Correct 224 ms 29124 KB Output is correct
22 Correct 215 ms 29348 KB Output is correct
23 Correct 221 ms 29256 KB Output is correct
24 Correct 215 ms 28532 KB Output is correct
25 Correct 216 ms 29064 KB Output is correct
26 Correct 209 ms 28528 KB Output is correct
27 Correct 6 ms 7488 KB Output is correct
28 Correct 6 ms 7488 KB Output is correct
29 Correct 6 ms 7484 KB Output is correct
30 Correct 6 ms 7584 KB Output is correct
31 Correct 6 ms 7500 KB Output is correct
32 Correct 5 ms 7500 KB Output is correct
33 Correct 6 ms 7500 KB Output is correct
34 Correct 6 ms 7484 KB Output is correct
35 Correct 6 ms 7636 KB Output is correct
36 Correct 21 ms 11608 KB Output is correct
37 Correct 139 ms 30384 KB Output is correct
38 Correct 156 ms 32508 KB Output is correct
39 Correct 185 ms 36164 KB Output is correct
40 Correct 202 ms 37360 KB Output is correct
41 Correct 239 ms 40632 KB Output is correct
42 Correct 218 ms 38348 KB Output is correct
43 Correct 152 ms 31164 KB Output is correct
44 Correct 124 ms 29072 KB Output is correct
45 Correct 116 ms 27960 KB Output is correct
46 Correct 263 ms 42256 KB Output is correct
47 Correct 30 ms 12024 KB Output is correct
48 Correct 245 ms 31792 KB Output is correct
49 Correct 322 ms 36000 KB Output is correct
50 Correct 374 ms 39188 KB Output is correct
51 Correct 422 ms 41260 KB Output is correct
52 Correct 434 ms 41224 KB Output is correct
53 Correct 383 ms 34092 KB Output is correct
54 Correct 279 ms 34232 KB Output is correct
55 Correct 237 ms 31920 KB Output is correct
56 Correct 252 ms 31696 KB Output is correct
57 Correct 490 ms 44452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7236 KB Output is correct
2 Correct 5 ms 7244 KB Output is correct
3 Correct 5 ms 7244 KB Output is correct
4 Correct 5 ms 7244 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7500 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 6 ms 7496 KB Output is correct
9 Correct 6 ms 7492 KB Output is correct
10 Correct 78 ms 21932 KB Output is correct
11 Correct 96 ms 24568 KB Output is correct
12 Correct 92 ms 24492 KB Output is correct
13 Correct 98 ms 25380 KB Output is correct
14 Correct 82 ms 22716 KB Output is correct
15 Correct 89 ms 22072 KB Output is correct
16 Correct 179 ms 27032 KB Output is correct
17 Correct 170 ms 26268 KB Output is correct
18 Correct 184 ms 27416 KB Output is correct
19 Correct 165 ms 24384 KB Output is correct
20 Correct 210 ms 28624 KB Output is correct
21 Correct 217 ms 29440 KB Output is correct
22 Correct 224 ms 29124 KB Output is correct
23 Correct 215 ms 29348 KB Output is correct
24 Correct 221 ms 29256 KB Output is correct
25 Correct 215 ms 28532 KB Output is correct
26 Correct 216 ms 29064 KB Output is correct
27 Correct 209 ms 28528 KB Output is correct
28 Correct 6 ms 7488 KB Output is correct
29 Correct 6 ms 7488 KB Output is correct
30 Correct 6 ms 7484 KB Output is correct
31 Correct 6 ms 7584 KB Output is correct
32 Correct 6 ms 7500 KB Output is correct
33 Correct 5 ms 7500 KB Output is correct
34 Correct 6 ms 7500 KB Output is correct
35 Correct 6 ms 7484 KB Output is correct
36 Correct 6 ms 7636 KB Output is correct
37 Correct 21 ms 11608 KB Output is correct
38 Correct 139 ms 30384 KB Output is correct
39 Correct 156 ms 32508 KB Output is correct
40 Correct 185 ms 36164 KB Output is correct
41 Correct 202 ms 37360 KB Output is correct
42 Correct 239 ms 40632 KB Output is correct
43 Correct 218 ms 38348 KB Output is correct
44 Correct 152 ms 31164 KB Output is correct
45 Correct 124 ms 29072 KB Output is correct
46 Correct 116 ms 27960 KB Output is correct
47 Correct 263 ms 42256 KB Output is correct
48 Correct 30 ms 12024 KB Output is correct
49 Correct 245 ms 31792 KB Output is correct
50 Correct 322 ms 36000 KB Output is correct
51 Correct 374 ms 39188 KB Output is correct
52 Correct 422 ms 41260 KB Output is correct
53 Correct 434 ms 41224 KB Output is correct
54 Correct 383 ms 34092 KB Output is correct
55 Correct 279 ms 34232 KB Output is correct
56 Correct 237 ms 31920 KB Output is correct
57 Correct 252 ms 31696 KB Output is correct
58 Correct 490 ms 44452 KB Output is correct
59 Correct 80 ms 15860 KB Output is correct
60 Correct 232 ms 31640 KB Output is correct
61 Correct 230 ms 31088 KB Output is correct
62 Correct 248 ms 32448 KB Output is correct
63 Correct 228 ms 29984 KB Output is correct
64 Correct 5 ms 7500 KB Output is correct
65 Correct 6 ms 7500 KB Output is correct
66 Correct 6 ms 7624 KB Output is correct
67 Correct 5 ms 7372 KB Output is correct
68 Correct 6 ms 7500 KB Output is correct
69 Correct 7 ms 7620 KB Output is correct
70 Correct 6 ms 7628 KB Output is correct
71 Correct 6 ms 7500 KB Output is correct
72 Correct 6 ms 7500 KB Output is correct
73 Correct 6 ms 7628 KB Output is correct
74 Correct 152 ms 28848 KB Output is correct
75 Correct 150 ms 31544 KB Output is correct
76 Correct 155 ms 31144 KB Output is correct
77 Correct 147 ms 29624 KB Output is correct
78 Correct 73 ms 16352 KB Output is correct
79 Correct 61 ms 14908 KB Output is correct
80 Correct 124 ms 25480 KB Output is correct
81 Correct 178 ms 34120 KB Output is correct
82 Correct 254 ms 39736 KB Output is correct
83 Correct 172 ms 32824 KB Output is correct
84 Correct 120 ms 28348 KB Output is correct
85 Correct 189 ms 33916 KB Output is correct
86 Correct 74 ms 16796 KB Output is correct
87 Correct 293 ms 34460 KB Output is correct
88 Correct 329 ms 37064 KB Output is correct
89 Correct 274 ms 31388 KB Output is correct
90 Correct 151 ms 18236 KB Output is correct
91 Correct 159 ms 19096 KB Output is correct
92 Correct 257 ms 28308 KB Output is correct
93 Correct 338 ms 37028 KB Output is correct
94 Correct 463 ms 42156 KB Output is correct
95 Correct 287 ms 34484 KB Output is correct
96 Correct 254 ms 31676 KB Output is correct
97 Correct 332 ms 36084 KB Output is correct