답안 #502996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502996 2022-01-06T21:27:20 Z sliviu 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
226 ms 22084 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

int construct(vector<vector<int>> p) {
	int n = p.size(), cur = 0, bad = 0;
	vector<vector<int>> ans(n, vector<int>(n));
	vector<int> seen(n), solved(n), cycle;
	function<void(int)> dfs = [&](int node) {
		if (bad)
			return;
		seen[node] = cur;
		int c1 = 0, c2 = 0;
		for (int i = 0; i < n; ++i)
			if (i != node) {
				if (p[node][i] == 1)
					++c1;
				else if (p[node][i] == 2)
					++c2;
				else if (p[node][i] == 3)
					bad = 1;
				if (!seen[i] && p[node][i])
					dfs(i);
				if (!p[node][i] && seen[i] == cur)
					bad = 1;
			}
		if (!c1 && c2)
			cycle.emplace_back(node);
		if (!solved[node] && c1) {
			if (c2)
				cycle.emplace_back(node);
			solved[node] = 1;
			int cur = node;
			for (int i = 0; i < n; ++i)
				if (i != node && p[node][i] == 1)
					ans[cur][i] = ans[i][cur] = solved[i] = 1, cur = i;
		}
	};
	for (int i = 0; i < n; ++i)
		if (!seen[i]) {
			cycle.clear();
			++cur;
			dfs(i);
			if (bad)
				return 0;
			if (!cycle.empty()) {
				if (cycle.size() == 2)
					return 0;
				int root = cycle[0], cur = root;
				for (auto x : cycle) {
					if (x != root) {
						ans[cur][x] = ans[x][cur] = 1;
						cur = x;
					}
				}
				ans[cur][root] = ans[root][cur] = 1;
			}
		}
	build(ans);
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 176 ms 22012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 176 ms 22012 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 268 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1100 KB Output is correct
13 Correct 164 ms 22012 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 80 ms 12044 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 46 ms 5684 KB Output is correct
21 Correct 171 ms 22052 KB Output is correct
22 Correct 173 ms 22012 KB Output is correct
23 Correct 175 ms 22020 KB Output is correct
24 Correct 180 ms 22020 KB Output is correct
25 Correct 72 ms 12100 KB Output is correct
26 Correct 74 ms 12028 KB Output is correct
27 Correct 185 ms 22012 KB Output is correct
28 Correct 226 ms 22012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 272 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 7 ms 1100 KB Output is correct
9 Correct 167 ms 21964 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1100 KB Output is correct
13 Correct 176 ms 22068 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 3 ms 704 KB Output is correct
17 Correct 74 ms 12028 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 45 ms 5668 KB Output is correct
22 Correct 177 ms 22080 KB Output is correct
23 Correct 188 ms 21972 KB Output is correct
24 Correct 179 ms 22012 KB Output is correct
25 Correct 70 ms 12024 KB Output is correct
26 Correct 97 ms 12100 KB Output is correct
27 Correct 174 ms 21960 KB Output is correct
28 Correct 175 ms 22020 KB Output is correct
29 Correct 79 ms 12080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 43 ms 5756 KB Output is correct
5 Correct 189 ms 22008 KB Output is correct
6 Correct 166 ms 22012 KB Output is correct
7 Correct 186 ms 22012 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 42 ms 5700 KB Output is correct
10 Correct 169 ms 22012 KB Output is correct
11 Correct 169 ms 21984 KB Output is correct
12 Correct 174 ms 22072 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 48 ms 5740 KB Output is correct
17 Correct 172 ms 22016 KB Output is correct
18 Correct 206 ms 22084 KB Output is correct
19 Correct 165 ms 22012 KB Output is correct
20 Correct 225 ms 22016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 176 ms 22012 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 268 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1100 KB Output is correct
13 Correct 164 ms 22012 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 80 ms 12044 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 46 ms 5684 KB Output is correct
21 Correct 171 ms 22052 KB Output is correct
22 Correct 173 ms 22012 KB Output is correct
23 Correct 175 ms 22020 KB Output is correct
24 Correct 180 ms 22020 KB Output is correct
25 Correct 72 ms 12100 KB Output is correct
26 Correct 74 ms 12028 KB Output is correct
27 Correct 185 ms 22012 KB Output is correct
28 Correct 226 ms 22012 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 272 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 7 ms 1100 KB Output is correct
37 Correct 167 ms 21964 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 8 ms 1100 KB Output is correct
41 Correct 176 ms 22068 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 3 ms 704 KB Output is correct
45 Correct 74 ms 12028 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 45 ms 5668 KB Output is correct
50 Correct 177 ms 22080 KB Output is correct
51 Correct 188 ms 21972 KB Output is correct
52 Correct 179 ms 22012 KB Output is correct
53 Correct 70 ms 12024 KB Output is correct
54 Correct 97 ms 12100 KB Output is correct
55 Correct 174 ms 21960 KB Output is correct
56 Correct 175 ms 22020 KB Output is correct
57 Correct 79 ms 12080 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 4 ms 716 KB Output is correct
61 Correct 73 ms 12024 KB Output is correct
62 Correct 0 ms 204 KB Output is correct
63 Correct 0 ms 204 KB Output is correct
64 Correct 0 ms 204 KB Output is correct
65 Correct 61 ms 5752 KB Output is correct
66 Correct 73 ms 12024 KB Output is correct
67 Correct 70 ms 12040 KB Output is correct
68 Correct 69 ms 12040 KB Output is correct
69 Correct 67 ms 12028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 7 ms 1100 KB Output is correct
7 Correct 176 ms 22012 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 268 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 8 ms 1100 KB Output is correct
13 Correct 164 ms 22012 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 4 ms 716 KB Output is correct
17 Correct 80 ms 12044 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 46 ms 5684 KB Output is correct
21 Correct 171 ms 22052 KB Output is correct
22 Correct 173 ms 22012 KB Output is correct
23 Correct 175 ms 22020 KB Output is correct
24 Correct 180 ms 22020 KB Output is correct
25 Correct 72 ms 12100 KB Output is correct
26 Correct 74 ms 12028 KB Output is correct
27 Correct 185 ms 22012 KB Output is correct
28 Correct 226 ms 22012 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 272 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 7 ms 1100 KB Output is correct
37 Correct 167 ms 21964 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 8 ms 1100 KB Output is correct
41 Correct 176 ms 22068 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 3 ms 704 KB Output is correct
45 Correct 74 ms 12028 KB Output is correct
46 Correct 0 ms 204 KB Output is correct
47 Correct 0 ms 204 KB Output is correct
48 Correct 1 ms 204 KB Output is correct
49 Correct 45 ms 5668 KB Output is correct
50 Correct 177 ms 22080 KB Output is correct
51 Correct 188 ms 21972 KB Output is correct
52 Correct 179 ms 22012 KB Output is correct
53 Correct 70 ms 12024 KB Output is correct
54 Correct 97 ms 12100 KB Output is correct
55 Correct 174 ms 21960 KB Output is correct
56 Correct 175 ms 22020 KB Output is correct
57 Correct 79 ms 12080 KB Output is correct
58 Correct 0 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 43 ms 5756 KB Output is correct
62 Correct 189 ms 22008 KB Output is correct
63 Correct 166 ms 22012 KB Output is correct
64 Correct 186 ms 22012 KB Output is correct
65 Correct 0 ms 204 KB Output is correct
66 Correct 42 ms 5700 KB Output is correct
67 Correct 169 ms 22012 KB Output is correct
68 Correct 169 ms 21984 KB Output is correct
69 Correct 174 ms 22072 KB Output is correct
70 Correct 1 ms 204 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 0 ms 204 KB Output is correct
73 Correct 48 ms 5740 KB Output is correct
74 Correct 172 ms 22016 KB Output is correct
75 Correct 206 ms 22084 KB Output is correct
76 Correct 165 ms 22012 KB Output is correct
77 Correct 225 ms 22016 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 0 ms 204 KB Output is correct
80 Correct 4 ms 716 KB Output is correct
81 Correct 73 ms 12024 KB Output is correct
82 Correct 0 ms 204 KB Output is correct
83 Correct 0 ms 204 KB Output is correct
84 Correct 0 ms 204 KB Output is correct
85 Correct 61 ms 5752 KB Output is correct
86 Correct 73 ms 12024 KB Output is correct
87 Correct 70 ms 12040 KB Output is correct
88 Correct 69 ms 12040 KB Output is correct
89 Correct 67 ms 12028 KB Output is correct
90 Correct 0 ms 204 KB Output is correct
91 Correct 0 ms 204 KB Output is correct
92 Correct 4 ms 716 KB Output is correct
93 Correct 82 ms 12028 KB Output is correct
94 Correct 1 ms 204 KB Output is correct
95 Correct 0 ms 204 KB Output is correct
96 Correct 0 ms 204 KB Output is correct
97 Correct 18 ms 3212 KB Output is correct
98 Correct 70 ms 12024 KB Output is correct
99 Correct 76 ms 12044 KB Output is correct
100 Correct 72 ms 12036 KB Output is correct
101 Correct 69 ms 12032 KB Output is correct
102 Correct 78 ms 12028 KB Output is correct
103 Correct 69 ms 12028 KB Output is correct
104 Correct 70 ms 12100 KB Output is correct
105 Correct 78 ms 12028 KB Output is correct