답안 #516709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516709 2022-01-22T02:38:46 Z pavement 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
211 ms 24316 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

int link[1005], sz[1005], link2[1005], sz2[1005];
vector<int> vec[1005], vec2[1005];

int find(int x) {
	if (x == link[x]) return x;
	return link[x] = find(link[x]);
}

void unite(int a, int b) {
	a = find(a);
	b = find(b);
	if (a == b) return;
	if (sz[b] > sz[a]) swap(a, b);
	sz[a] += sz[b];
	for (int i : vec[b]) vec[a].pb(i);
	link[b] = a;
}

int find2(int x) {
	if (x == link2[x]) return x;
	return link2[x] = find2(link2[x]);
}

void unite2(int a, int b) {
	a = find2(a);
	b = find2(b);
	if (a == b) return;
	if (sz2[b] > sz2[a]) swap(a, b);
	sz2[a] += sz2[b];
	for (int i : vec2[b]) vec2[a].pb(i);
	link2[b] = link2[a];
}

int construct(vector<vector<int> > p) {
	int n = p.size();
	vector<vector<int> > b(n, vector<int>(n, 0));
	for (int i = 0; i < n; i++) {
		link[i] = i;
		sz[i] = 1;
		link2[i] = i;
		sz2[i] = 1;
		vec[i].pb(i);
		vec2[i].pb(i);
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (p[i][j] == 1) unite(i, j);
			else if (p[i][j] == 3) return 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (p[i][j] == 2) unite2(find(i), find(j));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (p[i][j] == 0 && find2(find(i)) == find2(find(j))) return 0;
			else if (p[i][j] == 1 && find(i) != find(j)) return 0;
			else if (p[i][j] == 2 && (find2(find(i)) != find2(find(j)) || find(i) == find(j))) return 0;
	for (int i = 0; i < n; i++)
		if (i == find(i) && i == find2(i)) {
			if (vec2[i].size() == 2) return 0;
			else if (vec2[i].size() == 1) {
				for (int j = 0; j < (int)vec[i].size() - 1; j++)
					b[vec[i][j]][vec[i][j + 1]] = b[vec[i][j + 1]][vec[i][j]] = 1;
			} else {
				for (int j : vec2[i])
					for (int k = 0; k < (int)vec[j].size() - 1; k++)
						b[vec[j][k]][vec[j][k + 1]] = b[vec[j][k + 1]][vec[j][k]] = 1;
				for (int j = 0; j < (int)vec2[i].size() - 1; j++)
					b[vec2[i][j]][vec2[i][j + 1]] = b[vec2[i][j + 1]][vec2[i][j]] = 1;
				b[vec2[i][0]][vec2[i].back()] = b[vec2[i].back()][vec2[i][0]] = 1;
			}
		}
	build(b);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 7 ms 1220 KB Output is correct
7 Correct 175 ms 24068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 7 ms 1220 KB Output is correct
7 Correct 175 ms 24068 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 8 ms 1256 KB Output is correct
13 Correct 170 ms 24104 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 4 ms 836 KB Output is correct
17 Correct 80 ms 14180 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 43 ms 6296 KB Output is correct
21 Correct 165 ms 24100 KB Output is correct
22 Correct 171 ms 24132 KB Output is correct
23 Correct 194 ms 24104 KB Output is correct
24 Correct 198 ms 24100 KB Output is correct
25 Correct 69 ms 14116 KB Output is correct
26 Correct 66 ms 14148 KB Output is correct
27 Correct 205 ms 24016 KB Output is correct
28 Correct 163 ms 24108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 8 ms 1288 KB Output is correct
9 Correct 176 ms 24104 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 9 ms 1252 KB Output is correct
13 Correct 211 ms 24104 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 4 ms 868 KB Output is correct
17 Correct 106 ms 14112 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 46 ms 6312 KB Output is correct
22 Correct 189 ms 24220 KB Output is correct
23 Correct 165 ms 24100 KB Output is correct
24 Correct 193 ms 24156 KB Output is correct
25 Correct 68 ms 14120 KB Output is correct
26 Correct 75 ms 14244 KB Output is correct
27 Correct 165 ms 24096 KB Output is correct
28 Correct 200 ms 24104 KB Output is correct
29 Correct 94 ms 14108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 45 ms 6312 KB Output is correct
5 Correct 172 ms 24100 KB Output is correct
6 Correct 186 ms 24104 KB Output is correct
7 Correct 182 ms 24056 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 43 ms 6308 KB Output is correct
10 Correct 190 ms 24112 KB Output is correct
11 Correct 169 ms 24132 KB Output is correct
12 Correct 194 ms 24032 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 46 ms 6340 KB Output is correct
17 Correct 177 ms 24316 KB Output is correct
18 Correct 175 ms 24124 KB Output is correct
19 Correct 202 ms 24108 KB Output is correct
20 Correct 163 ms 24008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 7 ms 1220 KB Output is correct
7 Correct 175 ms 24068 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 8 ms 1256 KB Output is correct
13 Correct 170 ms 24104 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 4 ms 836 KB Output is correct
17 Correct 80 ms 14180 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 43 ms 6296 KB Output is correct
21 Correct 165 ms 24100 KB Output is correct
22 Correct 171 ms 24132 KB Output is correct
23 Correct 194 ms 24104 KB Output is correct
24 Correct 198 ms 24100 KB Output is correct
25 Correct 69 ms 14116 KB Output is correct
26 Correct 66 ms 14148 KB Output is correct
27 Correct 205 ms 24016 KB Output is correct
28 Correct 163 ms 24108 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 8 ms 1288 KB Output is correct
37 Correct 176 ms 24104 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 9 ms 1252 KB Output is correct
41 Correct 211 ms 24104 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 4 ms 868 KB Output is correct
45 Correct 106 ms 14112 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 46 ms 6312 KB Output is correct
50 Correct 189 ms 24220 KB Output is correct
51 Correct 165 ms 24100 KB Output is correct
52 Correct 193 ms 24156 KB Output is correct
53 Correct 68 ms 14120 KB Output is correct
54 Correct 75 ms 14244 KB Output is correct
55 Correct 165 ms 24096 KB Output is correct
56 Correct 200 ms 24104 KB Output is correct
57 Correct 94 ms 14108 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 4 ms 844 KB Output is correct
61 Correct 99 ms 14116 KB Output is correct
62 Correct 0 ms 332 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 52 ms 6340 KB Output is correct
66 Correct 70 ms 14112 KB Output is correct
67 Correct 69 ms 14124 KB Output is correct
68 Correct 68 ms 14116 KB Output is correct
69 Correct 71 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 7 ms 1220 KB Output is correct
7 Correct 175 ms 24068 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 8 ms 1256 KB Output is correct
13 Correct 170 ms 24104 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 4 ms 836 KB Output is correct
17 Correct 80 ms 14180 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 43 ms 6296 KB Output is correct
21 Correct 165 ms 24100 KB Output is correct
22 Correct 171 ms 24132 KB Output is correct
23 Correct 194 ms 24104 KB Output is correct
24 Correct 198 ms 24100 KB Output is correct
25 Correct 69 ms 14116 KB Output is correct
26 Correct 66 ms 14148 KB Output is correct
27 Correct 205 ms 24016 KB Output is correct
28 Correct 163 ms 24108 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 8 ms 1288 KB Output is correct
37 Correct 176 ms 24104 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 0 ms 332 KB Output is correct
40 Correct 9 ms 1252 KB Output is correct
41 Correct 211 ms 24104 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 4 ms 868 KB Output is correct
45 Correct 106 ms 14112 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 46 ms 6312 KB Output is correct
50 Correct 189 ms 24220 KB Output is correct
51 Correct 165 ms 24100 KB Output is correct
52 Correct 193 ms 24156 KB Output is correct
53 Correct 68 ms 14120 KB Output is correct
54 Correct 75 ms 14244 KB Output is correct
55 Correct 165 ms 24096 KB Output is correct
56 Correct 200 ms 24104 KB Output is correct
57 Correct 94 ms 14108 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 344 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 45 ms 6312 KB Output is correct
62 Correct 172 ms 24100 KB Output is correct
63 Correct 186 ms 24104 KB Output is correct
64 Correct 182 ms 24056 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 43 ms 6308 KB Output is correct
67 Correct 190 ms 24112 KB Output is correct
68 Correct 169 ms 24132 KB Output is correct
69 Correct 194 ms 24032 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 0 ms 344 KB Output is correct
73 Correct 46 ms 6340 KB Output is correct
74 Correct 177 ms 24316 KB Output is correct
75 Correct 175 ms 24124 KB Output is correct
76 Correct 202 ms 24108 KB Output is correct
77 Correct 163 ms 24008 KB Output is correct
78 Correct 1 ms 332 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 4 ms 844 KB Output is correct
81 Correct 99 ms 14116 KB Output is correct
82 Correct 0 ms 332 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 52 ms 6340 KB Output is correct
86 Correct 70 ms 14112 KB Output is correct
87 Correct 69 ms 14124 KB Output is correct
88 Correct 68 ms 14116 KB Output is correct
89 Correct 71 ms 14164 KB Output is correct
90 Correct 1 ms 344 KB Output is correct
91 Correct 1 ms 332 KB Output is correct
92 Correct 3 ms 844 KB Output is correct
93 Correct 69 ms 14116 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 332 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 17 ms 3728 KB Output is correct
98 Correct 66 ms 14112 KB Output is correct
99 Correct 71 ms 14116 KB Output is correct
100 Correct 65 ms 14128 KB Output is correct
101 Correct 70 ms 14112 KB Output is correct
102 Correct 66 ms 14180 KB Output is correct
103 Correct 83 ms 14116 KB Output is correct
104 Correct 68 ms 14244 KB Output is correct
105 Correct 75 ms 14116 KB Output is correct