#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int sz[1001],par[1001],vis[1001];
int find(int a){
if(a==par[a]) return a;
int x=find(par[a]);
par[a]=x;
return x;
}
void join(int x,int y){
x=find(x);
y=find(y);
if(x==y) return;
if(sz[x]<sz[y]) swap(x,y);
else if(sz[x]==sz[y] && x>y) swap(x,y);
sz[x]+=sz[y];
par[y]=x;
}
vector<pair<int,int>> node[4];
vector<int> v[1001],x,y;
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
for(int i=0;i<n;i++){
sz[i]=1;
par[i]=i;
for(int j=0;j<n;j++){
node[p[i][j]].push_back({i,j});
}
}
std::vector<std::vector<int>> answer(n,vector<int> (n,0));
for(auto [x,y]:node[1]) join(x,y);
for(int i=0;i<n;i++){
v[find(i)].push_back(i);
}
for(int i=0;i<n;i++){
if(v[i].size()==0) continue;
for(int j=1;j<v[i].size();j++){
vis[v[i][j]]=1;
answer[v[i][0]][v[i][j]]=answer[v[i][j]][v[i][0]]=1;
}
v[i].clear();
}
for(auto [x,y]:node[2]) join(x,y);
for(int i=0;i<n;i++){
if(!vis[i]) v[find(i)].push_back(i);
}
for(int i=0;i<n;i++){
if(v[i].size()<2) continue;
if(v[i].size()==2) return 0;
answer[v[i][0]][v[i].back()]=answer[v[i].back()][v[i][0]]=1;
for(int j=1;j<v[i].size();j++){
answer[v[i][j-1]][v[i][j]]=answer[v[i][j]][v[i][j-1]]=1;
}
}
if(node[3].size()!=0) return 0;
for(auto [x,y]:node[0]){
if(find(x)==find(y)) return 0;
}
build(answer);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int j=1;j<v[i].size();j++){
| ~^~~~~~~~~~~~
supertrees.cpp:53:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int j=1;j<v[i].size();j++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
9 ms |
1748 KB |
Output is correct |
7 |
Correct |
178 ms |
31988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
9 ms |
1748 KB |
Output is correct |
7 |
Correct |
178 ms |
31988 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1744 KB |
Output is correct |
13 |
Correct |
168 ms |
32004 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
1240 KB |
Output is correct |
17 |
Correct |
84 ms |
21992 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
42 ms |
8332 KB |
Output is correct |
21 |
Correct |
176 ms |
31912 KB |
Output is correct |
22 |
Correct |
167 ms |
31988 KB |
Output is correct |
23 |
Correct |
175 ms |
31980 KB |
Output is correct |
24 |
Correct |
163 ms |
32008 KB |
Output is correct |
25 |
Correct |
77 ms |
21984 KB |
Output is correct |
26 |
Correct |
78 ms |
22064 KB |
Output is correct |
27 |
Correct |
183 ms |
31844 KB |
Output is correct |
28 |
Correct |
172 ms |
32020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
9 ms |
1748 KB |
Output is correct |
9 |
Correct |
184 ms |
32320 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1780 KB |
Output is correct |
13 |
Correct |
167 ms |
32116 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
4 ms |
1368 KB |
Output is correct |
17 |
Correct |
89 ms |
21980 KB |
Output is correct |
18 |
Correct |
0 ms |
468 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
41 ms |
8336 KB |
Output is correct |
22 |
Correct |
166 ms |
32664 KB |
Output is correct |
23 |
Correct |
167 ms |
31860 KB |
Output is correct |
24 |
Correct |
178 ms |
32016 KB |
Output is correct |
25 |
Correct |
73 ms |
21952 KB |
Output is correct |
26 |
Correct |
74 ms |
21936 KB |
Output is correct |
27 |
Correct |
167 ms |
32112 KB |
Output is correct |
28 |
Correct |
165 ms |
31904 KB |
Output is correct |
29 |
Correct |
73 ms |
22012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
41 ms |
8360 KB |
Output is correct |
5 |
Correct |
161 ms |
31956 KB |
Output is correct |
6 |
Correct |
175 ms |
32180 KB |
Output is correct |
7 |
Correct |
164 ms |
31876 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
43 ms |
8372 KB |
Output is correct |
10 |
Correct |
164 ms |
32252 KB |
Output is correct |
11 |
Correct |
178 ms |
31928 KB |
Output is correct |
12 |
Correct |
173 ms |
31984 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
464 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
41 ms |
8284 KB |
Output is correct |
17 |
Correct |
170 ms |
32204 KB |
Output is correct |
18 |
Correct |
162 ms |
32464 KB |
Output is correct |
19 |
Correct |
159 ms |
31996 KB |
Output is correct |
20 |
Correct |
158 ms |
32180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
9 ms |
1748 KB |
Output is correct |
7 |
Correct |
178 ms |
31988 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1744 KB |
Output is correct |
13 |
Correct |
168 ms |
32004 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
1240 KB |
Output is correct |
17 |
Correct |
84 ms |
21992 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
42 ms |
8332 KB |
Output is correct |
21 |
Correct |
176 ms |
31912 KB |
Output is correct |
22 |
Correct |
167 ms |
31988 KB |
Output is correct |
23 |
Correct |
175 ms |
31980 KB |
Output is correct |
24 |
Correct |
163 ms |
32008 KB |
Output is correct |
25 |
Correct |
77 ms |
21984 KB |
Output is correct |
26 |
Correct |
78 ms |
22064 KB |
Output is correct |
27 |
Correct |
183 ms |
31844 KB |
Output is correct |
28 |
Correct |
172 ms |
32020 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
9 ms |
1748 KB |
Output is correct |
37 |
Correct |
184 ms |
32320 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1780 KB |
Output is correct |
41 |
Correct |
167 ms |
32116 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
4 ms |
1368 KB |
Output is correct |
45 |
Correct |
89 ms |
21980 KB |
Output is correct |
46 |
Correct |
0 ms |
468 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
41 ms |
8336 KB |
Output is correct |
50 |
Correct |
166 ms |
32664 KB |
Output is correct |
51 |
Correct |
167 ms |
31860 KB |
Output is correct |
52 |
Correct |
178 ms |
32016 KB |
Output is correct |
53 |
Correct |
73 ms |
21952 KB |
Output is correct |
54 |
Correct |
74 ms |
21936 KB |
Output is correct |
55 |
Correct |
167 ms |
32112 KB |
Output is correct |
56 |
Correct |
165 ms |
31904 KB |
Output is correct |
57 |
Correct |
73 ms |
22012 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
4 ms |
1368 KB |
Output is correct |
61 |
Correct |
86 ms |
22628 KB |
Output is correct |
62 |
Correct |
1 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
44 ms |
8384 KB |
Output is correct |
66 |
Correct |
75 ms |
22492 KB |
Output is correct |
67 |
Correct |
78 ms |
21980 KB |
Output is correct |
68 |
Correct |
79 ms |
21960 KB |
Output is correct |
69 |
Correct |
73 ms |
22208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
9 ms |
1748 KB |
Output is correct |
7 |
Correct |
178 ms |
31988 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1744 KB |
Output is correct |
13 |
Correct |
168 ms |
32004 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
1240 KB |
Output is correct |
17 |
Correct |
84 ms |
21992 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
600 KB |
Output is correct |
20 |
Correct |
42 ms |
8332 KB |
Output is correct |
21 |
Correct |
176 ms |
31912 KB |
Output is correct |
22 |
Correct |
167 ms |
31988 KB |
Output is correct |
23 |
Correct |
175 ms |
31980 KB |
Output is correct |
24 |
Correct |
163 ms |
32008 KB |
Output is correct |
25 |
Correct |
77 ms |
21984 KB |
Output is correct |
26 |
Correct |
78 ms |
22064 KB |
Output is correct |
27 |
Correct |
183 ms |
31844 KB |
Output is correct |
28 |
Correct |
172 ms |
32020 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
9 ms |
1748 KB |
Output is correct |
37 |
Correct |
184 ms |
32320 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1780 KB |
Output is correct |
41 |
Correct |
167 ms |
32116 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
4 ms |
1368 KB |
Output is correct |
45 |
Correct |
89 ms |
21980 KB |
Output is correct |
46 |
Correct |
0 ms |
468 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
41 ms |
8336 KB |
Output is correct |
50 |
Correct |
166 ms |
32664 KB |
Output is correct |
51 |
Correct |
167 ms |
31860 KB |
Output is correct |
52 |
Correct |
178 ms |
32016 KB |
Output is correct |
53 |
Correct |
73 ms |
21952 KB |
Output is correct |
54 |
Correct |
74 ms |
21936 KB |
Output is correct |
55 |
Correct |
167 ms |
32112 KB |
Output is correct |
56 |
Correct |
165 ms |
31904 KB |
Output is correct |
57 |
Correct |
73 ms |
22012 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
600 KB |
Output is correct |
61 |
Correct |
41 ms |
8360 KB |
Output is correct |
62 |
Correct |
161 ms |
31956 KB |
Output is correct |
63 |
Correct |
175 ms |
32180 KB |
Output is correct |
64 |
Correct |
164 ms |
31876 KB |
Output is correct |
65 |
Correct |
0 ms |
348 KB |
Output is correct |
66 |
Correct |
43 ms |
8372 KB |
Output is correct |
67 |
Correct |
164 ms |
32252 KB |
Output is correct |
68 |
Correct |
178 ms |
31928 KB |
Output is correct |
69 |
Correct |
173 ms |
31984 KB |
Output is correct |
70 |
Correct |
1 ms |
348 KB |
Output is correct |
71 |
Correct |
0 ms |
464 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
41 ms |
8284 KB |
Output is correct |
74 |
Correct |
170 ms |
32204 KB |
Output is correct |
75 |
Correct |
162 ms |
32464 KB |
Output is correct |
76 |
Correct |
159 ms |
31996 KB |
Output is correct |
77 |
Correct |
158 ms |
32180 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
1 ms |
348 KB |
Output is correct |
80 |
Correct |
4 ms |
1368 KB |
Output is correct |
81 |
Correct |
86 ms |
22628 KB |
Output is correct |
82 |
Correct |
1 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
1 ms |
348 KB |
Output is correct |
85 |
Correct |
44 ms |
8384 KB |
Output is correct |
86 |
Correct |
75 ms |
22492 KB |
Output is correct |
87 |
Correct |
78 ms |
21980 KB |
Output is correct |
88 |
Correct |
79 ms |
21960 KB |
Output is correct |
89 |
Correct |
73 ms |
22208 KB |
Output is correct |
90 |
Correct |
0 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
600 KB |
Output is correct |
92 |
Correct |
4 ms |
1372 KB |
Output is correct |
93 |
Correct |
99 ms |
22020 KB |
Output is correct |
94 |
Correct |
0 ms |
348 KB |
Output is correct |
95 |
Correct |
0 ms |
344 KB |
Output is correct |
96 |
Correct |
0 ms |
348 KB |
Output is correct |
97 |
Correct |
19 ms |
5900 KB |
Output is correct |
98 |
Correct |
73 ms |
22044 KB |
Output is correct |
99 |
Correct |
74 ms |
22236 KB |
Output is correct |
100 |
Correct |
72 ms |
21896 KB |
Output is correct |
101 |
Correct |
72 ms |
21948 KB |
Output is correct |
102 |
Correct |
72 ms |
22204 KB |
Output is correct |
103 |
Correct |
77 ms |
22144 KB |
Output is correct |
104 |
Correct |
75 ms |
22124 KB |
Output is correct |
105 |
Correct |
77 ms |
21936 KB |
Output is correct |