#include<bits/stdc++.h>
#include "supertrees.h"
#define MAXN 300007
using namespace std;
int n;
int dsu[MAXN],dsu2[MAXN];
vector<int> comp[MAXN],comp2[MAXN];
vector< vector<int> > ans;
int root(int x){
if(dsu[x]==x)return x;
dsu[x]=root(dsu[x]);
return dsu[x];
}
void mergev(int x,int y){
dsu[root(x)]=root(y);
}
int root2(int x){
if(dsu2[x]==x)return x;
dsu2[x]=root2(dsu2[x]);
return dsu2[x];
}
void mergev2(int x,int y){
dsu2[root2(x)]=root2(y);
}
void add_edge(int x,int y){
ans[x][y]=ans[y][x]=1;
}
int construct(vector< vector<int> > p){
n=int(p.size());
ans.resize(n);
for(int i=0;i<n;i++){
ans[i].resize(n);
}
for(int i=0;i<n;i++){
dsu[i]=dsu2[i]=i;
}
for(int i=0;i<n;i++){
for(int f=i+1;f<n;f++){
if(p[i][f]==1)mergev(i,f);
}
}
for(int i=0;i<n;i++){
comp[root(i)].push_back(i);
}
for(int i=0;i<n;i++){
if(comp[i].empty())continue;
for(int f=0;f<comp[i].size();f++){
for(int k=f+1;k<comp[i].size();k++){
if(p[comp[i][f]][comp[i][k]]!=1)return 0;
}
}
for(int f=0;f<comp[i].size()-1;f++){
add_edge(comp[i][f],comp[i][f+1]);
}
}
for(int i=0;i<n;i++){
for(int f=i+1;f<n;f++){
if(p[i][f]==2)mergev2(root(i),root(f));
}
}
for(int i=0;i<n;i++){
if(comp[i].empty())continue;
comp2[root2(i)].push_back(i);
}
for(int i=0;i<n;i++){
if(comp2[i].empty() or comp2[i].size()==1)continue;
if(comp2[i].size()==2)return 0;
for(int f=0;f<comp2[i].size();f++){
for(int k=f+1;k<comp2[i].size();k++){
for(int t:comp[comp2[i][f]]){
for(int s:comp[comp2[i][k]]){
if(p[t][s]!=2)return 0;
}
}
}
}
for(int f=0;f<comp2[i].size();f++){
add_edge(comp2[i][f],comp2[i][(f+1)%int(comp2[i].size())]);
}
}
build(ans);
/*
for(int i=0;i<ans.size();i++){
for(int f=0;f<ans.size();f++){
cout<<ans[i][f]<<" ";
}
cout<<"\n";
}
*/
return 1;
}
/*
int main(){
construct({{1, 1, 1,1}, {1, 1, 1,1}, {1,1,1,1}, {1,1,1,1}});
}
*/
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int f=0;f<comp[i].size();f++){
| ~^~~~~~~~~~~~~~~
supertrees.cpp:61:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int k=f+1;k<comp[i].size();k++){
| ~^~~~~~~~~~~~~~~
supertrees.cpp:65:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int f=0;f<comp[i].size()-1;f++){
| ~^~~~~~~~~~~~~~~~~
supertrees.cpp:85:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int f=0;f<comp2[i].size();f++){
| ~^~~~~~~~~~~~~~~~
supertrees.cpp:86:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int k=f+1;k<comp2[i].size();k++){
| ~^~~~~~~~~~~~~~~~
supertrees.cpp:94:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int f=0;f<comp2[i].size();f++){
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
6 ms |
14292 KB |
Output is correct |
4 |
Correct |
6 ms |
14292 KB |
Output is correct |
5 |
Correct |
6 ms |
14364 KB |
Output is correct |
6 |
Correct |
12 ms |
15288 KB |
Output is correct |
7 |
Correct |
161 ms |
36132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
6 ms |
14292 KB |
Output is correct |
4 |
Correct |
6 ms |
14292 KB |
Output is correct |
5 |
Correct |
6 ms |
14364 KB |
Output is correct |
6 |
Correct |
12 ms |
15288 KB |
Output is correct |
7 |
Correct |
161 ms |
36132 KB |
Output is correct |
8 |
Correct |
9 ms |
14292 KB |
Output is correct |
9 |
Correct |
6 ms |
14292 KB |
Output is correct |
10 |
Correct |
5 ms |
14292 KB |
Output is correct |
11 |
Correct |
6 ms |
14292 KB |
Output is correct |
12 |
Correct |
13 ms |
15204 KB |
Output is correct |
13 |
Correct |
156 ms |
36200 KB |
Output is correct |
14 |
Correct |
6 ms |
14292 KB |
Output is correct |
15 |
Correct |
8 ms |
14292 KB |
Output is correct |
16 |
Correct |
10 ms |
14804 KB |
Output is correct |
17 |
Correct |
77 ms |
26148 KB |
Output is correct |
18 |
Correct |
7 ms |
14292 KB |
Output is correct |
19 |
Correct |
6 ms |
14292 KB |
Output is correct |
20 |
Correct |
63 ms |
19764 KB |
Output is correct |
21 |
Correct |
160 ms |
36164 KB |
Output is correct |
22 |
Correct |
159 ms |
36064 KB |
Output is correct |
23 |
Correct |
170 ms |
36196 KB |
Output is correct |
24 |
Correct |
166 ms |
36212 KB |
Output is correct |
25 |
Correct |
72 ms |
26148 KB |
Output is correct |
26 |
Correct |
70 ms |
26136 KB |
Output is correct |
27 |
Correct |
164 ms |
36096 KB |
Output is correct |
28 |
Correct |
170 ms |
36124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14292 KB |
Output is correct |
2 |
Correct |
7 ms |
14292 KB |
Output is correct |
3 |
Correct |
7 ms |
14296 KB |
Output is correct |
4 |
Correct |
6 ms |
14292 KB |
Output is correct |
5 |
Correct |
8 ms |
14400 KB |
Output is correct |
6 |
Correct |
7 ms |
14396 KB |
Output is correct |
7 |
Correct |
8 ms |
14296 KB |
Output is correct |
8 |
Correct |
14 ms |
15308 KB |
Output is correct |
9 |
Correct |
160 ms |
38148 KB |
Output is correct |
10 |
Correct |
7 ms |
14400 KB |
Output is correct |
11 |
Correct |
6 ms |
14400 KB |
Output is correct |
12 |
Correct |
13 ms |
15316 KB |
Output is correct |
13 |
Correct |
170 ms |
38100 KB |
Output is correct |
14 |
Correct |
6 ms |
14292 KB |
Output is correct |
15 |
Correct |
6 ms |
14408 KB |
Output is correct |
16 |
Correct |
9 ms |
14860 KB |
Output is correct |
17 |
Correct |
79 ms |
28220 KB |
Output is correct |
18 |
Correct |
8 ms |
14400 KB |
Output is correct |
19 |
Correct |
6 ms |
14292 KB |
Output is correct |
20 |
Correct |
6 ms |
14404 KB |
Output is correct |
21 |
Correct |
48 ms |
20300 KB |
Output is correct |
22 |
Correct |
162 ms |
38092 KB |
Output is correct |
23 |
Correct |
165 ms |
38152 KB |
Output is correct |
24 |
Correct |
167 ms |
38104 KB |
Output is correct |
25 |
Correct |
85 ms |
28172 KB |
Output is correct |
26 |
Correct |
74 ms |
28168 KB |
Output is correct |
27 |
Correct |
157 ms |
38092 KB |
Output is correct |
28 |
Correct |
194 ms |
38124 KB |
Output is correct |
29 |
Correct |
70 ms |
28168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14392 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
7 ms |
14292 KB |
Output is correct |
4 |
Correct |
44 ms |
19824 KB |
Output is correct |
5 |
Correct |
158 ms |
36124 KB |
Output is correct |
6 |
Correct |
161 ms |
36260 KB |
Output is correct |
7 |
Correct |
163 ms |
36120 KB |
Output is correct |
8 |
Correct |
6 ms |
14296 KB |
Output is correct |
9 |
Correct |
43 ms |
19872 KB |
Output is correct |
10 |
Correct |
164 ms |
36124 KB |
Output is correct |
11 |
Correct |
163 ms |
36136 KB |
Output is correct |
12 |
Correct |
167 ms |
36128 KB |
Output is correct |
13 |
Correct |
8 ms |
14292 KB |
Output is correct |
14 |
Correct |
8 ms |
14292 KB |
Output is correct |
15 |
Correct |
8 ms |
14292 KB |
Output is correct |
16 |
Correct |
45 ms |
19776 KB |
Output is correct |
17 |
Correct |
167 ms |
36148 KB |
Output is correct |
18 |
Correct |
164 ms |
36172 KB |
Output is correct |
19 |
Correct |
160 ms |
36132 KB |
Output is correct |
20 |
Correct |
159 ms |
36172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
6 ms |
14292 KB |
Output is correct |
4 |
Correct |
6 ms |
14292 KB |
Output is correct |
5 |
Correct |
6 ms |
14364 KB |
Output is correct |
6 |
Correct |
12 ms |
15288 KB |
Output is correct |
7 |
Correct |
161 ms |
36132 KB |
Output is correct |
8 |
Correct |
9 ms |
14292 KB |
Output is correct |
9 |
Correct |
6 ms |
14292 KB |
Output is correct |
10 |
Correct |
5 ms |
14292 KB |
Output is correct |
11 |
Correct |
6 ms |
14292 KB |
Output is correct |
12 |
Correct |
13 ms |
15204 KB |
Output is correct |
13 |
Correct |
156 ms |
36200 KB |
Output is correct |
14 |
Correct |
6 ms |
14292 KB |
Output is correct |
15 |
Correct |
8 ms |
14292 KB |
Output is correct |
16 |
Correct |
10 ms |
14804 KB |
Output is correct |
17 |
Correct |
77 ms |
26148 KB |
Output is correct |
18 |
Correct |
7 ms |
14292 KB |
Output is correct |
19 |
Correct |
6 ms |
14292 KB |
Output is correct |
20 |
Correct |
63 ms |
19764 KB |
Output is correct |
21 |
Correct |
160 ms |
36164 KB |
Output is correct |
22 |
Correct |
159 ms |
36064 KB |
Output is correct |
23 |
Correct |
170 ms |
36196 KB |
Output is correct |
24 |
Correct |
166 ms |
36212 KB |
Output is correct |
25 |
Correct |
72 ms |
26148 KB |
Output is correct |
26 |
Correct |
70 ms |
26136 KB |
Output is correct |
27 |
Correct |
164 ms |
36096 KB |
Output is correct |
28 |
Correct |
170 ms |
36124 KB |
Output is correct |
29 |
Correct |
8 ms |
14292 KB |
Output is correct |
30 |
Correct |
7 ms |
14292 KB |
Output is correct |
31 |
Correct |
7 ms |
14296 KB |
Output is correct |
32 |
Correct |
6 ms |
14292 KB |
Output is correct |
33 |
Correct |
8 ms |
14400 KB |
Output is correct |
34 |
Correct |
7 ms |
14396 KB |
Output is correct |
35 |
Correct |
8 ms |
14296 KB |
Output is correct |
36 |
Correct |
14 ms |
15308 KB |
Output is correct |
37 |
Correct |
160 ms |
38148 KB |
Output is correct |
38 |
Correct |
7 ms |
14400 KB |
Output is correct |
39 |
Correct |
6 ms |
14400 KB |
Output is correct |
40 |
Correct |
13 ms |
15316 KB |
Output is correct |
41 |
Correct |
170 ms |
38100 KB |
Output is correct |
42 |
Correct |
6 ms |
14292 KB |
Output is correct |
43 |
Correct |
6 ms |
14408 KB |
Output is correct |
44 |
Correct |
9 ms |
14860 KB |
Output is correct |
45 |
Correct |
79 ms |
28220 KB |
Output is correct |
46 |
Correct |
8 ms |
14400 KB |
Output is correct |
47 |
Correct |
6 ms |
14292 KB |
Output is correct |
48 |
Correct |
6 ms |
14404 KB |
Output is correct |
49 |
Correct |
48 ms |
20300 KB |
Output is correct |
50 |
Correct |
162 ms |
38092 KB |
Output is correct |
51 |
Correct |
165 ms |
38152 KB |
Output is correct |
52 |
Correct |
167 ms |
38104 KB |
Output is correct |
53 |
Correct |
85 ms |
28172 KB |
Output is correct |
54 |
Correct |
74 ms |
28168 KB |
Output is correct |
55 |
Correct |
157 ms |
38092 KB |
Output is correct |
56 |
Correct |
194 ms |
38124 KB |
Output is correct |
57 |
Correct |
70 ms |
28168 KB |
Output is correct |
58 |
Correct |
7 ms |
14400 KB |
Output is correct |
59 |
Correct |
6 ms |
14292 KB |
Output is correct |
60 |
Correct |
11 ms |
14904 KB |
Output is correct |
61 |
Correct |
75 ms |
28084 KB |
Output is correct |
62 |
Correct |
9 ms |
14328 KB |
Output is correct |
63 |
Correct |
7 ms |
14400 KB |
Output is correct |
64 |
Correct |
7 ms |
14292 KB |
Output is correct |
65 |
Correct |
46 ms |
20360 KB |
Output is correct |
66 |
Correct |
79 ms |
28180 KB |
Output is correct |
67 |
Correct |
79 ms |
28168 KB |
Output is correct |
68 |
Correct |
71 ms |
28168 KB |
Output is correct |
69 |
Correct |
70 ms |
28180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
6 ms |
14292 KB |
Output is correct |
4 |
Correct |
6 ms |
14292 KB |
Output is correct |
5 |
Correct |
6 ms |
14364 KB |
Output is correct |
6 |
Correct |
12 ms |
15288 KB |
Output is correct |
7 |
Correct |
161 ms |
36132 KB |
Output is correct |
8 |
Correct |
9 ms |
14292 KB |
Output is correct |
9 |
Correct |
6 ms |
14292 KB |
Output is correct |
10 |
Correct |
5 ms |
14292 KB |
Output is correct |
11 |
Correct |
6 ms |
14292 KB |
Output is correct |
12 |
Correct |
13 ms |
15204 KB |
Output is correct |
13 |
Correct |
156 ms |
36200 KB |
Output is correct |
14 |
Correct |
6 ms |
14292 KB |
Output is correct |
15 |
Correct |
8 ms |
14292 KB |
Output is correct |
16 |
Correct |
10 ms |
14804 KB |
Output is correct |
17 |
Correct |
77 ms |
26148 KB |
Output is correct |
18 |
Correct |
7 ms |
14292 KB |
Output is correct |
19 |
Correct |
6 ms |
14292 KB |
Output is correct |
20 |
Correct |
63 ms |
19764 KB |
Output is correct |
21 |
Correct |
160 ms |
36164 KB |
Output is correct |
22 |
Correct |
159 ms |
36064 KB |
Output is correct |
23 |
Correct |
170 ms |
36196 KB |
Output is correct |
24 |
Correct |
166 ms |
36212 KB |
Output is correct |
25 |
Correct |
72 ms |
26148 KB |
Output is correct |
26 |
Correct |
70 ms |
26136 KB |
Output is correct |
27 |
Correct |
164 ms |
36096 KB |
Output is correct |
28 |
Correct |
170 ms |
36124 KB |
Output is correct |
29 |
Correct |
8 ms |
14292 KB |
Output is correct |
30 |
Correct |
7 ms |
14292 KB |
Output is correct |
31 |
Correct |
7 ms |
14296 KB |
Output is correct |
32 |
Correct |
6 ms |
14292 KB |
Output is correct |
33 |
Correct |
8 ms |
14400 KB |
Output is correct |
34 |
Correct |
7 ms |
14396 KB |
Output is correct |
35 |
Correct |
8 ms |
14296 KB |
Output is correct |
36 |
Correct |
14 ms |
15308 KB |
Output is correct |
37 |
Correct |
160 ms |
38148 KB |
Output is correct |
38 |
Correct |
7 ms |
14400 KB |
Output is correct |
39 |
Correct |
6 ms |
14400 KB |
Output is correct |
40 |
Correct |
13 ms |
15316 KB |
Output is correct |
41 |
Correct |
170 ms |
38100 KB |
Output is correct |
42 |
Correct |
6 ms |
14292 KB |
Output is correct |
43 |
Correct |
6 ms |
14408 KB |
Output is correct |
44 |
Correct |
9 ms |
14860 KB |
Output is correct |
45 |
Correct |
79 ms |
28220 KB |
Output is correct |
46 |
Correct |
8 ms |
14400 KB |
Output is correct |
47 |
Correct |
6 ms |
14292 KB |
Output is correct |
48 |
Correct |
6 ms |
14404 KB |
Output is correct |
49 |
Correct |
48 ms |
20300 KB |
Output is correct |
50 |
Correct |
162 ms |
38092 KB |
Output is correct |
51 |
Correct |
165 ms |
38152 KB |
Output is correct |
52 |
Correct |
167 ms |
38104 KB |
Output is correct |
53 |
Correct |
85 ms |
28172 KB |
Output is correct |
54 |
Correct |
74 ms |
28168 KB |
Output is correct |
55 |
Correct |
157 ms |
38092 KB |
Output is correct |
56 |
Correct |
194 ms |
38124 KB |
Output is correct |
57 |
Correct |
70 ms |
28168 KB |
Output is correct |
58 |
Correct |
7 ms |
14392 KB |
Output is correct |
59 |
Correct |
6 ms |
14292 KB |
Output is correct |
60 |
Correct |
7 ms |
14292 KB |
Output is correct |
61 |
Correct |
44 ms |
19824 KB |
Output is correct |
62 |
Correct |
158 ms |
36124 KB |
Output is correct |
63 |
Correct |
161 ms |
36260 KB |
Output is correct |
64 |
Correct |
163 ms |
36120 KB |
Output is correct |
65 |
Correct |
6 ms |
14296 KB |
Output is correct |
66 |
Correct |
43 ms |
19872 KB |
Output is correct |
67 |
Correct |
164 ms |
36124 KB |
Output is correct |
68 |
Correct |
163 ms |
36136 KB |
Output is correct |
69 |
Correct |
167 ms |
36128 KB |
Output is correct |
70 |
Correct |
8 ms |
14292 KB |
Output is correct |
71 |
Correct |
8 ms |
14292 KB |
Output is correct |
72 |
Correct |
8 ms |
14292 KB |
Output is correct |
73 |
Correct |
45 ms |
19776 KB |
Output is correct |
74 |
Correct |
167 ms |
36148 KB |
Output is correct |
75 |
Correct |
164 ms |
36172 KB |
Output is correct |
76 |
Correct |
160 ms |
36132 KB |
Output is correct |
77 |
Correct |
159 ms |
36172 KB |
Output is correct |
78 |
Correct |
7 ms |
14400 KB |
Output is correct |
79 |
Correct |
6 ms |
14292 KB |
Output is correct |
80 |
Correct |
11 ms |
14904 KB |
Output is correct |
81 |
Correct |
75 ms |
28084 KB |
Output is correct |
82 |
Correct |
9 ms |
14328 KB |
Output is correct |
83 |
Correct |
7 ms |
14400 KB |
Output is correct |
84 |
Correct |
7 ms |
14292 KB |
Output is correct |
85 |
Correct |
46 ms |
20360 KB |
Output is correct |
86 |
Correct |
79 ms |
28180 KB |
Output is correct |
87 |
Correct |
79 ms |
28168 KB |
Output is correct |
88 |
Correct |
71 ms |
28168 KB |
Output is correct |
89 |
Correct |
70 ms |
28180 KB |
Output is correct |
90 |
Correct |
6 ms |
14400 KB |
Output is correct |
91 |
Correct |
7 ms |
14376 KB |
Output is correct |
92 |
Correct |
9 ms |
14932 KB |
Output is correct |
93 |
Correct |
75 ms |
28172 KB |
Output is correct |
94 |
Correct |
6 ms |
14292 KB |
Output is correct |
95 |
Incorrect |
6 ms |
14400 KB |
Answer gives possible 1 while actual possible 0 |
96 |
Halted |
0 ms |
0 KB |
- |