#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#include "supertrees.h"
#define con(a, b) answer[a][b] = 1;answer[b][a] = 1;
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer(n, vector<int>(n, 0));
vector<vector<int>> groups;
vector<bool> assigned(n, 0);
for (int i = 0; i < n; i++)
{
if (assigned[i]) continue;
vector<int> cgroup;
vector<bool> ingroup(n, 0);
for (int j = 0; j < n; j++)
{
if (p[i][j] == 0) continue;
if (assigned[j]) {
return 0;
}
ingroup[j] = 1;
cgroup.push_back(j);
assigned[j] = 1;
}
for (int j : cgroup) {
for (int k = 0; k < n; k++)
{
if (ingroup[k] != (bool)p[j][k]) {
return 0;
}
}
}
groups.push_back(cgroup);
}
for (auto &g : groups) {
vector<vector<int>> branches;
vector<bool> br(n, 0);
for (int i : g) {
if (br[i]) continue;
vector<int> branch;
vector<bool> inbranch(n, 0);
for (int j : g) {
if (p[i][j] == 2) continue;
if (br[j]) return 0;
inbranch[j] = 1;
branch.push_back(j);
br[j] = 1;
}
for (int j : branch) {
for (int k : g) {
if (inbranch[k] != (p[j][k] == 1)) {
return 0;
}
}
}
branches.push_back(branch);
}
if (branches.size() == 2) return 0;
for (int i = 0; i < branches.size(); i++)
{
if (branches.size() != 1) {
con(branches[i][0], branches[(i+1)%branches.size()][0])
}
for (int j = 0; j < branches[i].size()-1; j++)
{
con(branches[i][j], branches[i][j+1])
}
}
}
build(answer);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:67:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0; i < branches.size(); i++)
| ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:72:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int j = 0; j < branches[i].size()-1; j++)
| ~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1140 KB |
Output is correct |
7 |
Correct |
163 ms |
22052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1140 KB |
Output is correct |
7 |
Correct |
163 ms |
22052 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 |
8 ms |
1136 KB |
Output is correct |
13 |
Correct |
173 ms |
22124 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
76 ms |
12036 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
5724 KB |
Output is correct |
21 |
Correct |
166 ms |
22008 KB |
Output is correct |
22 |
Correct |
168 ms |
22020 KB |
Output is correct |
23 |
Correct |
175 ms |
21964 KB |
Output is correct |
24 |
Correct |
174 ms |
22140 KB |
Output is correct |
25 |
Correct |
71 ms |
12036 KB |
Output is correct |
26 |
Correct |
71 ms |
12036 KB |
Output is correct |
27 |
Correct |
173 ms |
21968 KB |
Output is correct |
28 |
Correct |
176 ms |
22056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
8 ms |
1180 KB |
Output is correct |
9 |
Correct |
169 ms |
22020 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
7 ms |
1104 KB |
Output is correct |
13 |
Correct |
161 ms |
22004 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
74 ms |
12036 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 |
59 ms |
5768 KB |
Output is correct |
22 |
Correct |
169 ms |
21944 KB |
Output is correct |
23 |
Correct |
169 ms |
22064 KB |
Output is correct |
24 |
Correct |
180 ms |
22024 KB |
Output is correct |
25 |
Correct |
80 ms |
12160 KB |
Output is correct |
26 |
Correct |
70 ms |
12036 KB |
Output is correct |
27 |
Correct |
170 ms |
22016 KB |
Output is correct |
28 |
Correct |
176 ms |
22044 KB |
Output is correct |
29 |
Correct |
85 ms |
12164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
48 ms |
5692 KB |
Output is correct |
5 |
Correct |
166 ms |
22020 KB |
Output is correct |
6 |
Correct |
186 ms |
22016 KB |
Output is correct |
7 |
Correct |
188 ms |
22108 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
51 ms |
5764 KB |
Output is correct |
10 |
Correct |
167 ms |
22020 KB |
Output is correct |
11 |
Correct |
168 ms |
22012 KB |
Output is correct |
12 |
Correct |
205 ms |
22052 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
224 KB |
Output is correct |
16 |
Correct |
42 ms |
5696 KB |
Output is correct |
17 |
Correct |
220 ms |
22024 KB |
Output is correct |
18 |
Correct |
162 ms |
22128 KB |
Output is correct |
19 |
Correct |
173 ms |
21968 KB |
Output is correct |
20 |
Correct |
169 ms |
22020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1140 KB |
Output is correct |
7 |
Correct |
163 ms |
22052 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 |
8 ms |
1136 KB |
Output is correct |
13 |
Correct |
173 ms |
22124 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
76 ms |
12036 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
5724 KB |
Output is correct |
21 |
Correct |
166 ms |
22008 KB |
Output is correct |
22 |
Correct |
168 ms |
22020 KB |
Output is correct |
23 |
Correct |
175 ms |
21964 KB |
Output is correct |
24 |
Correct |
174 ms |
22140 KB |
Output is correct |
25 |
Correct |
71 ms |
12036 KB |
Output is correct |
26 |
Correct |
71 ms |
12036 KB |
Output is correct |
27 |
Correct |
173 ms |
21968 KB |
Output is correct |
28 |
Correct |
176 ms |
22056 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 |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 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 |
8 ms |
1180 KB |
Output is correct |
37 |
Correct |
169 ms |
22020 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
7 ms |
1104 KB |
Output is correct |
41 |
Correct |
161 ms |
22004 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
74 ms |
12036 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 |
59 ms |
5768 KB |
Output is correct |
50 |
Correct |
169 ms |
21944 KB |
Output is correct |
51 |
Correct |
169 ms |
22064 KB |
Output is correct |
52 |
Correct |
180 ms |
22024 KB |
Output is correct |
53 |
Correct |
80 ms |
12160 KB |
Output is correct |
54 |
Correct |
70 ms |
12036 KB |
Output is correct |
55 |
Correct |
170 ms |
22016 KB |
Output is correct |
56 |
Correct |
176 ms |
22044 KB |
Output is correct |
57 |
Correct |
85 ms |
12164 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
724 KB |
Output is correct |
61 |
Correct |
93 ms |
12044 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 |
5764 KB |
Output is correct |
66 |
Correct |
82 ms |
12048 KB |
Output is correct |
67 |
Correct |
78 ms |
12036 KB |
Output is correct |
68 |
Correct |
88 ms |
12040 KB |
Output is correct |
69 |
Correct |
71 ms |
12236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1140 KB |
Output is correct |
7 |
Correct |
163 ms |
22052 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 |
8 ms |
1136 KB |
Output is correct |
13 |
Correct |
173 ms |
22124 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
76 ms |
12036 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
5724 KB |
Output is correct |
21 |
Correct |
166 ms |
22008 KB |
Output is correct |
22 |
Correct |
168 ms |
22020 KB |
Output is correct |
23 |
Correct |
175 ms |
21964 KB |
Output is correct |
24 |
Correct |
174 ms |
22140 KB |
Output is correct |
25 |
Correct |
71 ms |
12036 KB |
Output is correct |
26 |
Correct |
71 ms |
12036 KB |
Output is correct |
27 |
Correct |
173 ms |
21968 KB |
Output is correct |
28 |
Correct |
176 ms |
22056 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 |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 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 |
8 ms |
1180 KB |
Output is correct |
37 |
Correct |
169 ms |
22020 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
256 KB |
Output is correct |
40 |
Correct |
7 ms |
1104 KB |
Output is correct |
41 |
Correct |
161 ms |
22004 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
74 ms |
12036 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 |
59 ms |
5768 KB |
Output is correct |
50 |
Correct |
169 ms |
21944 KB |
Output is correct |
51 |
Correct |
169 ms |
22064 KB |
Output is correct |
52 |
Correct |
180 ms |
22024 KB |
Output is correct |
53 |
Correct |
80 ms |
12160 KB |
Output is correct |
54 |
Correct |
70 ms |
12036 KB |
Output is correct |
55 |
Correct |
170 ms |
22016 KB |
Output is correct |
56 |
Correct |
176 ms |
22044 KB |
Output is correct |
57 |
Correct |
85 ms |
12164 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 |
48 ms |
5692 KB |
Output is correct |
62 |
Correct |
166 ms |
22020 KB |
Output is correct |
63 |
Correct |
186 ms |
22016 KB |
Output is correct |
64 |
Correct |
188 ms |
22108 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
51 ms |
5764 KB |
Output is correct |
67 |
Correct |
167 ms |
22020 KB |
Output is correct |
68 |
Correct |
168 ms |
22012 KB |
Output is correct |
69 |
Correct |
205 ms |
22052 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
224 KB |
Output is correct |
73 |
Correct |
42 ms |
5696 KB |
Output is correct |
74 |
Correct |
220 ms |
22024 KB |
Output is correct |
75 |
Correct |
162 ms |
22128 KB |
Output is correct |
76 |
Correct |
173 ms |
21968 KB |
Output is correct |
77 |
Correct |
169 ms |
22020 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
724 KB |
Output is correct |
81 |
Correct |
93 ms |
12044 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 |
5764 KB |
Output is correct |
86 |
Correct |
82 ms |
12048 KB |
Output is correct |
87 |
Correct |
78 ms |
12036 KB |
Output is correct |
88 |
Correct |
88 ms |
12040 KB |
Output is correct |
89 |
Correct |
71 ms |
12236 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
5 ms |
724 KB |
Output is correct |
93 |
Correct |
79 ms |
12044 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
0 ms |
212 KB |
Output is correct |
96 |
Correct |
0 ms |
212 KB |
Output is correct |
97 |
Correct |
17 ms |
3284 KB |
Output is correct |
98 |
Correct |
79 ms |
12108 KB |
Output is correct |
99 |
Correct |
68 ms |
12032 KB |
Output is correct |
100 |
Correct |
92 ms |
12036 KB |
Output is correct |
101 |
Correct |
83 ms |
12160 KB |
Output is correct |
102 |
Correct |
65 ms |
12032 KB |
Output is correct |
103 |
Correct |
63 ms |
12036 KB |
Output is correct |
104 |
Correct |
63 ms |
12032 KB |
Output is correct |
105 |
Correct |
77 ms |
12032 KB |
Output is correct |