답안 #779167

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779167 2023-07-11T08:36:59 Z Josia 슈퍼트리 잇기 (IOI20_supertrees) C++17
96 / 100
169 ms 23216 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>

using namespace std;




struct uf {
	vector<int> chefs;
	uf (int n) {
		chefs.resize(n);
		for (int i = 0; i<n; i++) chefs[i] = i;
	}

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

	void unite(int a, int b) {
		a = find(a);
		b = find(b);

		chefs[a] = b;
	}
};





int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	if (n == 1) {
		if (p[0][0] == 1) {
			build({{0}});
			return 1;
		}
		return 0;
	}

	// ----
	uf u(n);

	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			if (p[i][j]) u.unite(i, j);
		}
	}

	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			if ((bool)(p[i][j]) != (u.find(i) == u.find(j))) return 0;
		}
	}

	vector<vector<int>> vals(n);

	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			if (u.find(j) == i) vals[i].push_back(j);
		}
	}
	// ----


	uf u2(n);

	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			if (p[i][j]==1) u2.unite(i, j);
		}
	}

	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			if ((p[i][j]==1) != (u2.find(i) == u2.find(j))) return 0;
		}
	}

	vector<vector<int>> vals2(n);

	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			if (u2.find(j) == i) vals2[i].push_back(j);
		}
	}



	vector<vector<int>> secondConnect(n);

	vector<vector<int>> answer(n, vector<int>(n));

	for (auto v: vals2) {
		if (v.size()) secondConnect[u.find(v[0])].push_back(u2.find(v[0]));
		for (int i = 0; i<(int)(v.size())-1; i++) {
			answer[v[i]][v[(i+1)%v.size()]] = 1;
			answer[v[(i+1)%v.size()]][v[i]] = 1;
		}
	}

	for (auto v: secondConnect) {
		if (v.size() == 1) continue;
		if (v.size() == 2) return 0;
 
		for (int i = 0; i<(int)(v.size()); i++) {
			answer[v[i]][v[(i+1)%v.size()]] = 1;
			answer[v[(i+1)%v.size()]][v[i]] = 1;
		}
 
	}

	build(answer);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 248 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 1176 KB Output is correct
7 Correct 165 ms 22892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 248 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 1176 KB Output is correct
7 Correct 165 ms 22892 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 152 ms 23044 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 71 ms 9408 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 43 ms 6432 KB Output is correct
21 Correct 161 ms 22960 KB Output is correct
22 Correct 155 ms 22960 KB Output is correct
23 Correct 169 ms 22988 KB Output is correct
24 Correct 153 ms 23116 KB Output is correct
25 Correct 64 ms 9032 KB Output is correct
26 Correct 60 ms 9072 KB Output is correct
27 Correct 161 ms 22956 KB Output is correct
28 Correct 157 ms 23036 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 296 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 7 ms 1292 KB Output is correct
9 Correct 154 ms 23216 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 165 ms 23120 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 700 KB Output is correct
17 Correct 75 ms 9256 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 38 ms 6260 KB Output is correct
22 Correct 165 ms 23104 KB Output is correct
23 Correct 158 ms 23168 KB Output is correct
24 Correct 159 ms 23132 KB Output is correct
25 Correct 74 ms 14180 KB Output is correct
26 Correct 68 ms 10080 KB Output is correct
27 Correct 153 ms 23120 KB Output is correct
28 Correct 164 ms 23152 KB Output is correct
29 Correct 67 ms 14216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 39 ms 6260 KB Output is correct
5 Correct 156 ms 22868 KB Output is correct
6 Correct 160 ms 22832 KB Output is correct
7 Correct 164 ms 22888 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 39 ms 6208 KB Output is correct
10 Correct 154 ms 22360 KB Output is correct
11 Correct 151 ms 22380 KB Output is correct
12 Correct 159 ms 22396 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 39 ms 5936 KB Output is correct
17 Correct 152 ms 22352 KB Output is correct
18 Correct 158 ms 22372 KB Output is correct
19 Correct 155 ms 22384 KB Output is correct
20 Correct 151 ms 22440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 248 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 1176 KB Output is correct
7 Correct 165 ms 22892 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 152 ms 23044 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 71 ms 9408 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 43 ms 6432 KB Output is correct
21 Correct 161 ms 22960 KB Output is correct
22 Correct 155 ms 22960 KB Output is correct
23 Correct 169 ms 22988 KB Output is correct
24 Correct 153 ms 23116 KB Output is correct
25 Correct 64 ms 9032 KB Output is correct
26 Correct 60 ms 9072 KB Output is correct
27 Correct 161 ms 22956 KB Output is correct
28 Correct 157 ms 23036 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 296 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1292 KB Output is correct
37 Correct 154 ms 23216 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1212 KB Output is correct
41 Correct 165 ms 23120 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 700 KB Output is correct
45 Correct 75 ms 9256 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 38 ms 6260 KB Output is correct
50 Correct 165 ms 23104 KB Output is correct
51 Correct 158 ms 23168 KB Output is correct
52 Correct 159 ms 23132 KB Output is correct
53 Correct 74 ms 14180 KB Output is correct
54 Correct 68 ms 10080 KB Output is correct
55 Correct 153 ms 23120 KB Output is correct
56 Correct 164 ms 23152 KB Output is correct
57 Correct 67 ms 14216 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 3 ms 596 KB Output is correct
61 Correct 76 ms 10100 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 42 ms 6252 KB Output is correct
66 Correct 60 ms 10108 KB Output is correct
67 Correct 60 ms 10112 KB Output is correct
68 Correct 59 ms 10032 KB Output is correct
69 Correct 70 ms 14196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 248 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 1176 KB Output is correct
7 Correct 165 ms 22892 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 152 ms 23044 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 71 ms 9408 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 43 ms 6432 KB Output is correct
21 Correct 161 ms 22960 KB Output is correct
22 Correct 155 ms 22960 KB Output is correct
23 Correct 169 ms 22988 KB Output is correct
24 Correct 153 ms 23116 KB Output is correct
25 Correct 64 ms 9032 KB Output is correct
26 Correct 60 ms 9072 KB Output is correct
27 Correct 161 ms 22956 KB Output is correct
28 Correct 157 ms 23036 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 296 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1292 KB Output is correct
37 Correct 154 ms 23216 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 7 ms 1212 KB Output is correct
41 Correct 165 ms 23120 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 700 KB Output is correct
45 Correct 75 ms 9256 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 38 ms 6260 KB Output is correct
50 Correct 165 ms 23104 KB Output is correct
51 Correct 158 ms 23168 KB Output is correct
52 Correct 159 ms 23132 KB Output is correct
53 Correct 74 ms 14180 KB Output is correct
54 Correct 68 ms 10080 KB Output is correct
55 Correct 153 ms 23120 KB Output is correct
56 Correct 164 ms 23152 KB Output is correct
57 Correct 67 ms 14216 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 296 KB Output is correct
60 Correct 1 ms 300 KB Output is correct
61 Correct 39 ms 6260 KB Output is correct
62 Correct 156 ms 22868 KB Output is correct
63 Correct 160 ms 22832 KB Output is correct
64 Correct 164 ms 22888 KB Output is correct
65 Correct 1 ms 300 KB Output is correct
66 Correct 39 ms 6208 KB Output is correct
67 Correct 154 ms 22360 KB Output is correct
68 Correct 151 ms 22380 KB Output is correct
69 Correct 159 ms 22396 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 304 KB Output is correct
73 Correct 39 ms 5936 KB Output is correct
74 Correct 152 ms 22352 KB Output is correct
75 Correct 158 ms 22372 KB Output is correct
76 Correct 155 ms 22384 KB Output is correct
77 Correct 151 ms 22440 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 3 ms 596 KB Output is correct
81 Correct 76 ms 10100 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 42 ms 6252 KB Output is correct
86 Correct 60 ms 10108 KB Output is correct
87 Correct 60 ms 10112 KB Output is correct
88 Correct 59 ms 10032 KB Output is correct
89 Correct 70 ms 14196 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 300 KB Output is correct
92 Correct 4 ms 596 KB Output is correct
93 Correct 70 ms 10024 KB Output is correct
94 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -