#include <bits/stdc++.h>
#define pb push_back
using namespace std;
struct Dsu{
vector<int> s, p;
Dsu(int n){
s.resize(n + 1, 1);
p.resize(n + 1);
for(int i = 0; i <= n; ++i) p[i] = i;
}
int find(int v){
if(p[v] == v) return v;
return (p[v] = find(p[v]));
}
void merge(int a, int b){
a = find(a);
b = find(b);
if(a != b){
if(s[a] > s[b]) swap(a, b);
p[a] = b;
s[b] += s[a];
}
}
};
void build(vector<vector<int>> _b);
int construct(vector<vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
Dsu d(n);
vector<vector<int>> comp;
bool ok = 1;
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
if(p[i][j] == 3){
return 0;
}
if(p[i][j] != 0){
d.merge(i, j);
}
}
}
vector<int> s (n, -1);
for(int i = 0; i < n; ++i){
int c = d.find(i);
if(s[c] == -1){
s[c] = comp.size();
comp.pb({i});
}else{
comp[s[c]].pb(i);
}
}
vector<bool> used(n);
for(auto v: comp){
vector<int> in, notin;
for(int x: v){
bool inner = 1;
for(int y: v){
if(p[x][y] == 0){
return 0;
}
if(p[x][y] != 2 && x != y) inner = 0;
}
if(inner){
in.pb(x);
used[x] = 1;
}else{
notin.pb(x);
}
}
for(int u: notin){
if(used[u]){
continue;
}
used[u] = 1;
in.pb(u);
vector<int> q;
q.pb(u);
for(int x: notin){
if(p[u][x] == 1 && u != x){
if(used[x]){
return 0;
}
q.pb(x);
used[x] = 1;
}
}
for(int a: q){
for(int b: q){
if(p[a][b] != 1){
return 0;
}
}
}
for(int j = 0; j < q.size() - 1; ++j){
answer[q[j]][q[j + 1]] = 1;
answer[q[j + 1]][q[j]] = 1;
}
}
if(in.size() == 2){
return 0;
}
if(in.size() > 1){
for(int j = 0; j < in.size(); ++j){
answer[in[j]][in[(j + 1) % (in.size())]] = 1;
answer[in[(j + 1) % (in.size())]][in[j]] = 1;
}
}
}
build(answer);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:104:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(int j = 0; j < q.size() - 1; ++j){
| ~~^~~~~~~~~~~~~~
supertrees.cpp:113:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(int j = 0; j < in.size(); ++j){
| ~~^~~~~~~~~~~
supertrees.cpp:40:7: warning: unused variable 'ok' [-Wunused-variable]
40 | bool ok = 1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1108 KB |
Output is correct |
7 |
Correct |
176 ms |
21964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1108 KB |
Output is correct |
7 |
Correct |
176 ms |
21964 KB |
Output is correct |
8 |
Correct |
1 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 |
1108 KB |
Output is correct |
13 |
Correct |
170 ms |
22100 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 |
712 KB |
Output is correct |
17 |
Correct |
107 ms |
12032 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
44 ms |
5708 KB |
Output is correct |
21 |
Correct |
175 ms |
22052 KB |
Output is correct |
22 |
Correct |
170 ms |
22020 KB |
Output is correct |
23 |
Correct |
187 ms |
22024 KB |
Output is correct |
24 |
Correct |
167 ms |
22016 KB |
Output is correct |
25 |
Correct |
73 ms |
12032 KB |
Output is correct |
26 |
Correct |
70 ms |
12160 KB |
Output is correct |
27 |
Correct |
180 ms |
21992 KB |
Output is correct |
28 |
Correct |
161 ms |
22028 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 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 |
296 KB |
Output is correct |
8 |
Correct |
7 ms |
1244 KB |
Output is correct |
9 |
Correct |
167 ms |
22164 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 |
188 ms |
22188 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
852 KB |
Output is correct |
17 |
Correct |
92 ms |
12164 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
51 ms |
5804 KB |
Output is correct |
22 |
Correct |
190 ms |
22128 KB |
Output is correct |
23 |
Correct |
166 ms |
22196 KB |
Output is correct |
24 |
Correct |
173 ms |
22204 KB |
Output is correct |
25 |
Correct |
72 ms |
12292 KB |
Output is correct |
26 |
Correct |
83 ms |
12224 KB |
Output is correct |
27 |
Correct |
161 ms |
22120 KB |
Output is correct |
28 |
Correct |
199 ms |
22148 KB |
Output is correct |
29 |
Correct |
80 ms |
12320 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 |
45 ms |
5708 KB |
Output is correct |
5 |
Correct |
192 ms |
22020 KB |
Output is correct |
6 |
Correct |
165 ms |
22140 KB |
Output is correct |
7 |
Correct |
184 ms |
21964 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
48 ms |
5764 KB |
Output is correct |
10 |
Correct |
172 ms |
22032 KB |
Output is correct |
11 |
Correct |
172 ms |
22092 KB |
Output is correct |
12 |
Correct |
183 ms |
22024 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 |
212 KB |
Output is correct |
16 |
Correct |
49 ms |
5732 KB |
Output is correct |
17 |
Correct |
190 ms |
22020 KB |
Output is correct |
18 |
Correct |
169 ms |
21964 KB |
Output is correct |
19 |
Correct |
163 ms |
22056 KB |
Output is correct |
20 |
Correct |
176 ms |
22180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1108 KB |
Output is correct |
7 |
Correct |
176 ms |
21964 KB |
Output is correct |
8 |
Correct |
1 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 |
1108 KB |
Output is correct |
13 |
Correct |
170 ms |
22100 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 |
712 KB |
Output is correct |
17 |
Correct |
107 ms |
12032 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
44 ms |
5708 KB |
Output is correct |
21 |
Correct |
175 ms |
22052 KB |
Output is correct |
22 |
Correct |
170 ms |
22020 KB |
Output is correct |
23 |
Correct |
187 ms |
22024 KB |
Output is correct |
24 |
Correct |
167 ms |
22016 KB |
Output is correct |
25 |
Correct |
73 ms |
12032 KB |
Output is correct |
26 |
Correct |
70 ms |
12160 KB |
Output is correct |
27 |
Correct |
180 ms |
21992 KB |
Output is correct |
28 |
Correct |
161 ms |
22028 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 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 |
296 KB |
Output is correct |
36 |
Correct |
7 ms |
1244 KB |
Output is correct |
37 |
Correct |
167 ms |
22164 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 |
1236 KB |
Output is correct |
41 |
Correct |
188 ms |
22188 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
6 ms |
852 KB |
Output is correct |
45 |
Correct |
92 ms |
12164 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
304 KB |
Output is correct |
49 |
Correct |
51 ms |
5804 KB |
Output is correct |
50 |
Correct |
190 ms |
22128 KB |
Output is correct |
51 |
Correct |
166 ms |
22196 KB |
Output is correct |
52 |
Correct |
173 ms |
22204 KB |
Output is correct |
53 |
Correct |
72 ms |
12292 KB |
Output is correct |
54 |
Correct |
83 ms |
12224 KB |
Output is correct |
55 |
Correct |
161 ms |
22120 KB |
Output is correct |
56 |
Correct |
199 ms |
22148 KB |
Output is correct |
57 |
Correct |
80 ms |
12320 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 |
824 KB |
Output is correct |
61 |
Correct |
78 ms |
14072 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 |
300 KB |
Output is correct |
65 |
Correct |
61 ms |
6272 KB |
Output is correct |
66 |
Correct |
70 ms |
14072 KB |
Output is correct |
67 |
Correct |
71 ms |
14028 KB |
Output is correct |
68 |
Correct |
71 ms |
14028 KB |
Output is correct |
69 |
Correct |
75 ms |
14116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1108 KB |
Output is correct |
7 |
Correct |
176 ms |
21964 KB |
Output is correct |
8 |
Correct |
1 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 |
1108 KB |
Output is correct |
13 |
Correct |
170 ms |
22100 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 |
712 KB |
Output is correct |
17 |
Correct |
107 ms |
12032 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
44 ms |
5708 KB |
Output is correct |
21 |
Correct |
175 ms |
22052 KB |
Output is correct |
22 |
Correct |
170 ms |
22020 KB |
Output is correct |
23 |
Correct |
187 ms |
22024 KB |
Output is correct |
24 |
Correct |
167 ms |
22016 KB |
Output is correct |
25 |
Correct |
73 ms |
12032 KB |
Output is correct |
26 |
Correct |
70 ms |
12160 KB |
Output is correct |
27 |
Correct |
180 ms |
21992 KB |
Output is correct |
28 |
Correct |
161 ms |
22028 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 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 |
296 KB |
Output is correct |
36 |
Correct |
7 ms |
1244 KB |
Output is correct |
37 |
Correct |
167 ms |
22164 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 |
1236 KB |
Output is correct |
41 |
Correct |
188 ms |
22188 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
6 ms |
852 KB |
Output is correct |
45 |
Correct |
92 ms |
12164 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
304 KB |
Output is correct |
49 |
Correct |
51 ms |
5804 KB |
Output is correct |
50 |
Correct |
190 ms |
22128 KB |
Output is correct |
51 |
Correct |
166 ms |
22196 KB |
Output is correct |
52 |
Correct |
173 ms |
22204 KB |
Output is correct |
53 |
Correct |
72 ms |
12292 KB |
Output is correct |
54 |
Correct |
83 ms |
12224 KB |
Output is correct |
55 |
Correct |
161 ms |
22120 KB |
Output is correct |
56 |
Correct |
199 ms |
22148 KB |
Output is correct |
57 |
Correct |
80 ms |
12320 KB |
Output is correct |
58 |
Correct |
1 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 |
45 ms |
5708 KB |
Output is correct |
62 |
Correct |
192 ms |
22020 KB |
Output is correct |
63 |
Correct |
165 ms |
22140 KB |
Output is correct |
64 |
Correct |
184 ms |
21964 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
48 ms |
5764 KB |
Output is correct |
67 |
Correct |
172 ms |
22032 KB |
Output is correct |
68 |
Correct |
172 ms |
22092 KB |
Output is correct |
69 |
Correct |
183 ms |
22024 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 |
212 KB |
Output is correct |
73 |
Correct |
49 ms |
5732 KB |
Output is correct |
74 |
Correct |
190 ms |
22020 KB |
Output is correct |
75 |
Correct |
169 ms |
21964 KB |
Output is correct |
76 |
Correct |
163 ms |
22056 KB |
Output is correct |
77 |
Correct |
176 ms |
22180 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 |
824 KB |
Output is correct |
81 |
Correct |
78 ms |
14072 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 |
300 KB |
Output is correct |
85 |
Correct |
61 ms |
6272 KB |
Output is correct |
86 |
Correct |
70 ms |
14072 KB |
Output is correct |
87 |
Correct |
71 ms |
14028 KB |
Output is correct |
88 |
Correct |
71 ms |
14028 KB |
Output is correct |
89 |
Correct |
75 ms |
14116 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
3 ms |
824 KB |
Output is correct |
93 |
Correct |
75 ms |
14068 KB |
Output is correct |
94 |
Correct |
1 ms |
300 KB |
Output is correct |
95 |
Correct |
2 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
20 ms |
3700 KB |
Output is correct |
98 |
Correct |
78 ms |
14156 KB |
Output is correct |
99 |
Correct |
71 ms |
14080 KB |
Output is correct |
100 |
Correct |
68 ms |
14068 KB |
Output is correct |
101 |
Correct |
71 ms |
14028 KB |
Output is correct |
102 |
Correct |
71 ms |
14068 KB |
Output is correct |
103 |
Correct |
76 ms |
14072 KB |
Output is correct |
104 |
Correct |
92 ms |
14064 KB |
Output is correct |
105 |
Correct |
90 ms |
14068 KB |
Output is correct |