답안 #781055

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781055 2023-07-12T16:26:21 Z zsombor 슈퍼트리 잇기 (IOI20_supertrees) C++17
100 / 100
175 ms 27980 KB
#include "supertrees.h"
#include <vector>
using namespace std;

int n;
bool impossible = false;
vector <vector <int>> P;
vector <vector <int>> E;

void solve_comp(vector <int>& c) {
	int cnt = 0;
	vector <int> tree(n);
	vector <int> root;
	for (int& i : c) {
		tree[i] = cnt;
		for (int& j : c) { if (i == j) break; if (P[i][j] == 1) tree[i] = tree[j]; }
		for (int& j : c) {
			if (i == j) break;
			if (P[i][j] == 1 && tree[i] != tree[j]) impossible = true;
			if (P[i][j] == 2 && tree[i] == tree[j]) impossible = true;
		}
		if (tree[i] == cnt) { root.push_back(i); cnt++; }
	}
	for (int& i : c) if (i != root[tree[i]]) E[i][root[tree[i]]] = E[root[tree[i]]][i] = 1;
	if (cnt == 1) return;
	if (cnt == 2) { impossible = true; return; }
	for (int i = 1; i < root.size(); i++) E[root[i]][root[i - 1]] = E[root[i - 1]][root[i]] = 1;
	E[root[0]][root.back()] = E[root.back()][root[0]] = 1;
}

int construct(vector <vector <int>> p) {
	n = p.size();
	P = p;
	E.resize(n);
	for (int i = 0; i < n; i++) E[i].assign(n, 0);
	
	int cnt = 0;
	vector <int> comp(n);
	vector <vector <int>> C(n + 1);
	for (int i = 0; i < n; i++) {
		comp[i] = cnt;
		for (int j = 0; j < i; j++) if (P[i][j]) comp[i] = comp[j];
		for (int j = 0; j < i; j++) {
			if (P[i][j] == 3) return 0;
			if (P[i][j] && comp[i] != comp[j]) return 0;
			if (!P[i][j] && comp[i] == comp[j]) return 0;
		}
		C[comp[i]].push_back(i);
		if (comp[i] == cnt) cnt++;
	}

	for (int i = 0; i < cnt; i++) solve_comp(C[i]);
	if (impossible) return 0;
	build(E);
	return 1;
}

Compilation message

supertrees.cpp: In function 'void solve_comp(std::vector<int>&)':
supertrees.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for (int i = 1; i < root.size(); i++) E[root[i]][root[i - 1]] = E[root[i - 1]][root[i]] = 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 166 ms 25956 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 166 ms 25956 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1284 KB Output is correct
13 Correct 175 ms 25984 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 75 ms 15988 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 6652 KB Output is correct
21 Correct 171 ms 25972 KB Output is correct
22 Correct 166 ms 25976 KB Output is correct
23 Correct 173 ms 25932 KB Output is correct
24 Correct 166 ms 25972 KB Output is correct
25 Correct 72 ms 16076 KB Output is correct
26 Correct 73 ms 15992 KB Output is correct
27 Correct 171 ms 25976 KB Output is correct
28 Correct 168 ms 25944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1236 KB Output is correct
9 Correct 166 ms 25972 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 164 ms 26108 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 73 ms 15996 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 41 ms 6652 KB Output is correct
22 Correct 167 ms 26104 KB Output is correct
23 Correct 167 ms 25984 KB Output is correct
24 Correct 168 ms 25932 KB Output is correct
25 Correct 72 ms 16120 KB Output is correct
26 Correct 69 ms 16004 KB Output is correct
27 Correct 167 ms 25996 KB Output is correct
28 Correct 170 ms 26112 KB Output is correct
29 Correct 72 ms 16120 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 212 KB Output is correct
4 Correct 42 ms 6652 KB Output is correct
5 Correct 170 ms 25972 KB Output is correct
6 Correct 167 ms 25988 KB Output is correct
7 Correct 171 ms 25932 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 42 ms 6696 KB Output is correct
10 Correct 170 ms 25976 KB Output is correct
11 Correct 167 ms 25988 KB Output is correct
12 Correct 172 ms 25928 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 292 KB Output is correct
16 Correct 45 ms 7164 KB Output is correct
17 Correct 166 ms 27892 KB Output is correct
18 Correct 164 ms 27884 KB Output is correct
19 Correct 164 ms 27884 KB Output is correct
20 Correct 166 ms 27980 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 166 ms 25956 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1284 KB Output is correct
13 Correct 175 ms 25984 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 75 ms 15988 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 6652 KB Output is correct
21 Correct 171 ms 25972 KB Output is correct
22 Correct 166 ms 25976 KB Output is correct
23 Correct 173 ms 25932 KB Output is correct
24 Correct 166 ms 25972 KB Output is correct
25 Correct 72 ms 16076 KB Output is correct
26 Correct 73 ms 15992 KB Output is correct
27 Correct 171 ms 25976 KB Output is correct
28 Correct 168 ms 25944 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 166 ms 25972 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 164 ms 26108 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 73 ms 15996 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 41 ms 6652 KB Output is correct
50 Correct 167 ms 26104 KB Output is correct
51 Correct 167 ms 25984 KB Output is correct
52 Correct 168 ms 25932 KB Output is correct
53 Correct 72 ms 16120 KB Output is correct
54 Correct 69 ms 16004 KB Output is correct
55 Correct 167 ms 25996 KB Output is correct
56 Correct 170 ms 26112 KB Output is correct
57 Correct 72 ms 16120 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 852 KB Output is correct
61 Correct 70 ms 16000 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 41 ms 7148 KB Output is correct
66 Correct 69 ms 18024 KB Output is correct
67 Correct 69 ms 18020 KB Output is correct
68 Correct 72 ms 18024 KB Output is correct
69 Correct 70 ms 18020 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 166 ms 25956 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1284 KB Output is correct
13 Correct 175 ms 25984 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 75 ms 15988 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 43 ms 6652 KB Output is correct
21 Correct 171 ms 25972 KB Output is correct
22 Correct 166 ms 25976 KB Output is correct
23 Correct 173 ms 25932 KB Output is correct
24 Correct 166 ms 25972 KB Output is correct
25 Correct 72 ms 16076 KB Output is correct
26 Correct 73 ms 15992 KB Output is correct
27 Correct 171 ms 25976 KB Output is correct
28 Correct 168 ms 25944 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1236 KB Output is correct
37 Correct 166 ms 25972 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1236 KB Output is correct
41 Correct 164 ms 26108 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 73 ms 15996 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 41 ms 6652 KB Output is correct
50 Correct 167 ms 26104 KB Output is correct
51 Correct 167 ms 25984 KB Output is correct
52 Correct 168 ms 25932 KB Output is correct
53 Correct 72 ms 16120 KB Output is correct
54 Correct 69 ms 16004 KB Output is correct
55 Correct 167 ms 25996 KB Output is correct
56 Correct 170 ms 26112 KB Output is correct
57 Correct 72 ms 16120 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 42 ms 6652 KB Output is correct
62 Correct 170 ms 25972 KB Output is correct
63 Correct 167 ms 25988 KB Output is correct
64 Correct 171 ms 25932 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 42 ms 6696 KB Output is correct
67 Correct 170 ms 25976 KB Output is correct
68 Correct 167 ms 25988 KB Output is correct
69 Correct 172 ms 25928 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 0 ms 292 KB Output is correct
73 Correct 45 ms 7164 KB Output is correct
74 Correct 166 ms 27892 KB Output is correct
75 Correct 164 ms 27884 KB Output is correct
76 Correct 164 ms 27884 KB Output is correct
77 Correct 166 ms 27980 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 852 KB Output is correct
81 Correct 70 ms 16000 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 41 ms 7148 KB Output is correct
86 Correct 69 ms 18024 KB Output is correct
87 Correct 69 ms 18020 KB Output is correct
88 Correct 72 ms 18024 KB Output is correct
89 Correct 70 ms 18020 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 980 KB Output is correct
93 Correct 68 ms 17952 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 340 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 18 ms 4712 KB Output is correct
98 Correct 70 ms 18036 KB Output is correct
99 Correct 69 ms 18032 KB Output is correct
100 Correct 70 ms 18028 KB Output is correct
101 Correct 69 ms 17972 KB Output is correct
102 Correct 69 ms 18156 KB Output is correct
103 Correct 66 ms 18020 KB Output is correct
104 Correct 65 ms 18020 KB Output is correct
105 Correct 70 ms 18024 KB Output is correct