#include <bits/stdc++.h>
#define forint(i, N) for (int i = 0; i < (N); i++)
using namespace std;
void build(vector< vector<int> > b);
int construct(vector< vector<int> > p) {
int n = p.size();
//vector<int> coor(n, -1);
vector< vector<int> > ans(n, vector<int>(n, 0));
vector<int> visited(n, false);
vector< vector<int> > p2(n, vector<int>(n, 0));
forint(i, n) {
//cerr << i << endl;
if (!visited[i]) {
vector< vector<int> > tree;
visited[i] = true;
//if (coor[i] == -1) {
//coor[i] == i;
tree.push_back({i});
vector<int> tmp;
//tmp.push_back(i);
for (int j = i + 1; j < n; j++) {
if (p[i][j] == 3) {
return 0;
}
if (p[i][j] == 1) {
//if (coor[j] != -1) {
if (visited[j]) {
return 0;
}
//coor[j] = i;
ans[i][j] = 1;
ans[j][i] = 1;
visited[j] = true;
tree[tree.size()-1].push_back(j);
}
if (p[i][j] == 2) {
//cerr << "eh " << j << endl;
tmp.push_back(j);
}
}
if (tmp.size() == 1) {
return 0;
}
if (tmp.size() > 1) {
int last_node = i;
for (int k = 0; k < tmp.size(); k++) {
if (!visited[tmp[k]]) {
visited[tmp[k]] = true;
tree.push_back({tmp[k]});
ans[last_node][tmp[k]] = 1;
ans[tmp[k]][last_node] = 1;
last_node = tmp[k];
for (int k2 = k+1; k2 < tmp.size(); k2++) {
if (!visited[tmp[k2]] && p[tmp[k]][tmp[k2]] == 1) {
visited[tmp[k2]] = true;
ans[tmp[k]][tmp[k2]] = 1;
ans[tmp[k2]][tmp[k]] = 1;
tree[tree.size()-1].push_back(tmp[k2]);
}
}
}
}
ans[last_node][i] = 1;
ans[i][last_node] = 1;
}
//tree.push_back(tmp);
/*
cerr << i << "-----" << endl;
for (auto a : tree) {
for (auto b: a) {
cerr << b << " ";
}
cerr << endl;
}
cerr << "-----" << endl;
*/
for (int k = 0; k < tree.size(); k++) {
for (auto a : tree[k]) {
for (auto b : tree[k]) {
p2[a][b] = 1;
}
}
for (int k2 = k+1; k2 < tree.size(); k2++) {
for (auto a : tree[k]) {
for (auto b : tree[k2]) {
p2[a][b] = 2;
p2[b][a] = 2;
}
}
}
}
}
/*
else {
forint(j, n) {
if (p[i][j] != p[coor[i]][j]) {
return 0;
}
}
}
*/
}
forint(i, n) {
forint(j, n) {
if (p[i][j] != p2[i][j]) {
//cerr << i << " " << j << "---" << p2[i][j] << endl;
return 0;
}
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for (int k = 0; k < tmp.size(); k++) {
| ~~^~~~~~~~~~~~
supertrees.cpp:78:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int k2 = k+1; k2 < tmp.size(); k2++) {
| ~~~^~~~~~~~~~~~
supertrees.cpp:105:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for (int k = 0; k < tree.size(); k++) {
| ~~^~~~~~~~~~~~~
supertrees.cpp:113:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for (int k2 = k+1; k2 < tree.size(); k2++) {
| ~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1356 KB |
Output is correct |
7 |
Correct |
245 ms |
27888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1356 KB |
Output is correct |
7 |
Correct |
245 ms |
27888 KB |
Output is correct |
8 |
Correct |
1 ms |
272 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1400 KB |
Output is correct |
13 |
Correct |
245 ms |
28044 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
972 KB |
Output is correct |
17 |
Correct |
109 ms |
18044 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
61 ms |
7160 KB |
Output is correct |
21 |
Correct |
245 ms |
27908 KB |
Output is correct |
22 |
Correct |
252 ms |
27904 KB |
Output is correct |
23 |
Correct |
251 ms |
28032 KB |
Output is correct |
24 |
Correct |
249 ms |
27884 KB |
Output is correct |
25 |
Correct |
106 ms |
18244 KB |
Output is correct |
26 |
Correct |
103 ms |
18048 KB |
Output is correct |
27 |
Correct |
249 ms |
27876 KB |
Output is correct |
28 |
Correct |
244 ms |
27844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
296 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
11 ms |
1368 KB |
Output is correct |
9 |
Correct |
241 ms |
27924 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
248 ms |
28044 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
972 KB |
Output is correct |
17 |
Correct |
111 ms |
18036 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
61 ms |
7160 KB |
Output is correct |
22 |
Correct |
246 ms |
27892 KB |
Output is correct |
23 |
Correct |
250 ms |
28180 KB |
Output is correct |
24 |
Correct |
254 ms |
27896 KB |
Output is correct |
25 |
Correct |
106 ms |
17988 KB |
Output is correct |
26 |
Correct |
104 ms |
18040 KB |
Output is correct |
27 |
Correct |
242 ms |
27948 KB |
Output is correct |
28 |
Correct |
251 ms |
27972 KB |
Output is correct |
29 |
Correct |
104 ms |
17988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
220 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
62 ms |
7152 KB |
Output is correct |
5 |
Correct |
242 ms |
27944 KB |
Output is correct |
6 |
Correct |
243 ms |
27844 KB |
Output is correct |
7 |
Correct |
251 ms |
27972 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
61 ms |
7176 KB |
Output is correct |
10 |
Correct |
249 ms |
27912 KB |
Output is correct |
11 |
Correct |
240 ms |
27844 KB |
Output is correct |
12 |
Correct |
259 ms |
28020 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
61 ms |
7156 KB |
Output is correct |
17 |
Correct |
248 ms |
27952 KB |
Output is correct |
18 |
Correct |
245 ms |
27908 KB |
Output is correct |
19 |
Correct |
241 ms |
27872 KB |
Output is correct |
20 |
Correct |
244 ms |
27960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1356 KB |
Output is correct |
7 |
Correct |
245 ms |
27888 KB |
Output is correct |
8 |
Correct |
1 ms |
272 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1400 KB |
Output is correct |
13 |
Correct |
245 ms |
28044 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
972 KB |
Output is correct |
17 |
Correct |
109 ms |
18044 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
61 ms |
7160 KB |
Output is correct |
21 |
Correct |
245 ms |
27908 KB |
Output is correct |
22 |
Correct |
252 ms |
27904 KB |
Output is correct |
23 |
Correct |
251 ms |
28032 KB |
Output is correct |
24 |
Correct |
249 ms |
27884 KB |
Output is correct |
25 |
Correct |
106 ms |
18244 KB |
Output is correct |
26 |
Correct |
103 ms |
18048 KB |
Output is correct |
27 |
Correct |
249 ms |
27876 KB |
Output is correct |
28 |
Correct |
244 ms |
27844 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
296 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
11 ms |
1368 KB |
Output is correct |
37 |
Correct |
241 ms |
27924 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
248 ms |
28044 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
972 KB |
Output is correct |
45 |
Correct |
111 ms |
18036 KB |
Output is correct |
46 |
Correct |
1 ms |
208 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
61 ms |
7160 KB |
Output is correct |
50 |
Correct |
246 ms |
27892 KB |
Output is correct |
51 |
Correct |
250 ms |
28180 KB |
Output is correct |
52 |
Correct |
254 ms |
27896 KB |
Output is correct |
53 |
Correct |
106 ms |
17988 KB |
Output is correct |
54 |
Correct |
104 ms |
18040 KB |
Output is correct |
55 |
Correct |
242 ms |
27948 KB |
Output is correct |
56 |
Correct |
251 ms |
27972 KB |
Output is correct |
57 |
Correct |
104 ms |
17988 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
5 ms |
948 KB |
Output is correct |
61 |
Correct |
109 ms |
18032 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
204 KB |
Output is correct |
64 |
Correct |
1 ms |
204 KB |
Output is correct |
65 |
Correct |
64 ms |
7272 KB |
Output is correct |
66 |
Correct |
105 ms |
18048 KB |
Output is correct |
67 |
Correct |
107 ms |
18044 KB |
Output is correct |
68 |
Correct |
101 ms |
17992 KB |
Output is correct |
69 |
Correct |
101 ms |
18036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
11 ms |
1356 KB |
Output is correct |
7 |
Correct |
245 ms |
27888 KB |
Output is correct |
8 |
Correct |
1 ms |
272 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1400 KB |
Output is correct |
13 |
Correct |
245 ms |
28044 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
972 KB |
Output is correct |
17 |
Correct |
109 ms |
18044 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
61 ms |
7160 KB |
Output is correct |
21 |
Correct |
245 ms |
27908 KB |
Output is correct |
22 |
Correct |
252 ms |
27904 KB |
Output is correct |
23 |
Correct |
251 ms |
28032 KB |
Output is correct |
24 |
Correct |
249 ms |
27884 KB |
Output is correct |
25 |
Correct |
106 ms |
18244 KB |
Output is correct |
26 |
Correct |
103 ms |
18048 KB |
Output is correct |
27 |
Correct |
249 ms |
27876 KB |
Output is correct |
28 |
Correct |
244 ms |
27844 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
296 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
11 ms |
1368 KB |
Output is correct |
37 |
Correct |
241 ms |
27924 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
248 ms |
28044 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
5 ms |
972 KB |
Output is correct |
45 |
Correct |
111 ms |
18036 KB |
Output is correct |
46 |
Correct |
1 ms |
208 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
61 ms |
7160 KB |
Output is correct |
50 |
Correct |
246 ms |
27892 KB |
Output is correct |
51 |
Correct |
250 ms |
28180 KB |
Output is correct |
52 |
Correct |
254 ms |
27896 KB |
Output is correct |
53 |
Correct |
106 ms |
17988 KB |
Output is correct |
54 |
Correct |
104 ms |
18040 KB |
Output is correct |
55 |
Correct |
242 ms |
27948 KB |
Output is correct |
56 |
Correct |
251 ms |
27972 KB |
Output is correct |
57 |
Correct |
104 ms |
17988 KB |
Output is correct |
58 |
Correct |
1 ms |
220 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
62 ms |
7152 KB |
Output is correct |
62 |
Correct |
242 ms |
27944 KB |
Output is correct |
63 |
Correct |
243 ms |
27844 KB |
Output is correct |
64 |
Correct |
251 ms |
27972 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
61 ms |
7176 KB |
Output is correct |
67 |
Correct |
249 ms |
27912 KB |
Output is correct |
68 |
Correct |
240 ms |
27844 KB |
Output is correct |
69 |
Correct |
259 ms |
28020 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
1 ms |
204 KB |
Output is correct |
73 |
Correct |
61 ms |
7156 KB |
Output is correct |
74 |
Correct |
248 ms |
27952 KB |
Output is correct |
75 |
Correct |
245 ms |
27908 KB |
Output is correct |
76 |
Correct |
241 ms |
27872 KB |
Output is correct |
77 |
Correct |
244 ms |
27960 KB |
Output is correct |
78 |
Correct |
1 ms |
204 KB |
Output is correct |
79 |
Correct |
1 ms |
204 KB |
Output is correct |
80 |
Correct |
5 ms |
948 KB |
Output is correct |
81 |
Correct |
109 ms |
18032 KB |
Output is correct |
82 |
Correct |
1 ms |
204 KB |
Output is correct |
83 |
Correct |
1 ms |
204 KB |
Output is correct |
84 |
Correct |
1 ms |
204 KB |
Output is correct |
85 |
Correct |
64 ms |
7272 KB |
Output is correct |
86 |
Correct |
105 ms |
18048 KB |
Output is correct |
87 |
Correct |
107 ms |
18044 KB |
Output is correct |
88 |
Correct |
101 ms |
17992 KB |
Output is correct |
89 |
Correct |
101 ms |
18036 KB |
Output is correct |
90 |
Correct |
1 ms |
204 KB |
Output is correct |
91 |
Correct |
1 ms |
204 KB |
Output is correct |
92 |
Correct |
5 ms |
972 KB |
Output is correct |
93 |
Correct |
105 ms |
18036 KB |
Output is correct |
94 |
Correct |
1 ms |
204 KB |
Output is correct |
95 |
Correct |
1 ms |
204 KB |
Output is correct |
96 |
Correct |
1 ms |
204 KB |
Output is correct |
97 |
Correct |
26 ms |
4708 KB |
Output is correct |
98 |
Correct |
108 ms |
18044 KB |
Output is correct |
99 |
Correct |
103 ms |
18036 KB |
Output is correct |
100 |
Correct |
102 ms |
18036 KB |
Output is correct |
101 |
Correct |
105 ms |
18052 KB |
Output is correct |
102 |
Correct |
99 ms |
18048 KB |
Output is correct |
103 |
Correct |
102 ms |
17988 KB |
Output is correct |
104 |
Correct |
100 ms |
17988 KB |
Output is correct |
105 |
Correct |
108 ms |
17960 KB |
Output is correct |