#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);
if(p[i][f]==3)return 0;
}
}
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:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int f=0;f<comp[i].size();f++){
| ~^~~~~~~~~~~~~~~
supertrees.cpp:62:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int k=f+1;k<comp[i].size();k++){
| ~^~~~~~~~~~~~~~~
supertrees.cpp:66:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(int f=0;f<comp[i].size()-1;f++){
| ~^~~~~~~~~~~~~~~~~
supertrees.cpp:86:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int f=0;f<comp2[i].size();f++){
| ~^~~~~~~~~~~~~~~~
supertrees.cpp:87:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | for(int k=f+1;k<comp2[i].size();k++){
| ~^~~~~~~~~~~~~~~~
supertrees.cpp:95:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int f=0;f<comp2[i].size();f++){
| ~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
9 ms |
14356 KB |
Output is correct |
4 |
Correct |
7 ms |
14420 KB |
Output is correct |
5 |
Correct |
6 ms |
14292 KB |
Output is correct |
6 |
Correct |
13 ms |
15188 KB |
Output is correct |
7 |
Correct |
164 ms |
36124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
9 ms |
14356 KB |
Output is correct |
4 |
Correct |
7 ms |
14420 KB |
Output is correct |
5 |
Correct |
6 ms |
14292 KB |
Output is correct |
6 |
Correct |
13 ms |
15188 KB |
Output is correct |
7 |
Correct |
164 ms |
36124 KB |
Output is correct |
8 |
Correct |
6 ms |
14292 KB |
Output is correct |
9 |
Correct |
6 ms |
14284 KB |
Output is correct |
10 |
Correct |
6 ms |
14292 KB |
Output is correct |
11 |
Correct |
6 ms |
14312 KB |
Output is correct |
12 |
Correct |
13 ms |
15284 KB |
Output is correct |
13 |
Correct |
162 ms |
36120 KB |
Output is correct |
14 |
Correct |
7 ms |
14292 KB |
Output is correct |
15 |
Correct |
7 ms |
14320 KB |
Output is correct |
16 |
Correct |
10 ms |
14836 KB |
Output is correct |
17 |
Correct |
78 ms |
26132 KB |
Output is correct |
18 |
Correct |
6 ms |
14292 KB |
Output is correct |
19 |
Correct |
8 ms |
14292 KB |
Output is correct |
20 |
Correct |
51 ms |
19860 KB |
Output is correct |
21 |
Correct |
170 ms |
36044 KB |
Output is correct |
22 |
Correct |
162 ms |
36072 KB |
Output is correct |
23 |
Correct |
193 ms |
36120 KB |
Output is correct |
24 |
Correct |
162 ms |
36120 KB |
Output is correct |
25 |
Correct |
74 ms |
26148 KB |
Output is correct |
26 |
Correct |
74 ms |
26136 KB |
Output is correct |
27 |
Correct |
170 ms |
36120 KB |
Output is correct |
28 |
Correct |
160 ms |
36168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 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 |
7 ms |
14336 KB |
Output is correct |
5 |
Correct |
7 ms |
14292 KB |
Output is correct |
6 |
Correct |
7 ms |
14292 KB |
Output is correct |
7 |
Correct |
7 ms |
14292 KB |
Output is correct |
8 |
Correct |
15 ms |
15272 KB |
Output is correct |
9 |
Correct |
160 ms |
36116 KB |
Output is correct |
10 |
Correct |
6 ms |
14292 KB |
Output is correct |
11 |
Correct |
6 ms |
14292 KB |
Output is correct |
12 |
Correct |
13 ms |
15188 KB |
Output is correct |
13 |
Correct |
169 ms |
36116 KB |
Output is correct |
14 |
Correct |
6 ms |
14292 KB |
Output is correct |
15 |
Correct |
7 ms |
14292 KB |
Output is correct |
16 |
Correct |
10 ms |
14832 KB |
Output is correct |
17 |
Correct |
79 ms |
26276 KB |
Output is correct |
18 |
Correct |
6 ms |
14292 KB |
Output is correct |
19 |
Correct |
6 ms |
14292 KB |
Output is correct |
20 |
Correct |
7 ms |
14292 KB |
Output is correct |
21 |
Correct |
47 ms |
19820 KB |
Output is correct |
22 |
Correct |
162 ms |
36108 KB |
Output is correct |
23 |
Correct |
160 ms |
36136 KB |
Output is correct |
24 |
Correct |
181 ms |
36260 KB |
Output is correct |
25 |
Correct |
72 ms |
26268 KB |
Output is correct |
26 |
Correct |
73 ms |
26264 KB |
Output is correct |
27 |
Correct |
162 ms |
36136 KB |
Output is correct |
28 |
Correct |
168 ms |
36108 KB |
Output is correct |
29 |
Correct |
72 ms |
26260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14352 KB |
Output is correct |
2 |
Correct |
7 ms |
14292 KB |
Output is correct |
3 |
Correct |
7 ms |
14312 KB |
Output is correct |
4 |
Correct |
46 ms |
19848 KB |
Output is correct |
5 |
Correct |
162 ms |
36152 KB |
Output is correct |
6 |
Correct |
167 ms |
36124 KB |
Output is correct |
7 |
Correct |
172 ms |
36064 KB |
Output is correct |
8 |
Correct |
7 ms |
14292 KB |
Output is correct |
9 |
Correct |
47 ms |
19872 KB |
Output is correct |
10 |
Correct |
165 ms |
36172 KB |
Output is correct |
11 |
Correct |
191 ms |
36196 KB |
Output is correct |
12 |
Correct |
170 ms |
36120 KB |
Output is correct |
13 |
Correct |
6 ms |
14292 KB |
Output is correct |
14 |
Correct |
6 ms |
14292 KB |
Output is correct |
15 |
Correct |
7 ms |
14292 KB |
Output is correct |
16 |
Correct |
50 ms |
19872 KB |
Output is correct |
17 |
Correct |
192 ms |
36120 KB |
Output is correct |
18 |
Correct |
163 ms |
36112 KB |
Output is correct |
19 |
Correct |
161 ms |
36136 KB |
Output is correct |
20 |
Correct |
162 ms |
36116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
9 ms |
14356 KB |
Output is correct |
4 |
Correct |
7 ms |
14420 KB |
Output is correct |
5 |
Correct |
6 ms |
14292 KB |
Output is correct |
6 |
Correct |
13 ms |
15188 KB |
Output is correct |
7 |
Correct |
164 ms |
36124 KB |
Output is correct |
8 |
Correct |
6 ms |
14292 KB |
Output is correct |
9 |
Correct |
6 ms |
14284 KB |
Output is correct |
10 |
Correct |
6 ms |
14292 KB |
Output is correct |
11 |
Correct |
6 ms |
14312 KB |
Output is correct |
12 |
Correct |
13 ms |
15284 KB |
Output is correct |
13 |
Correct |
162 ms |
36120 KB |
Output is correct |
14 |
Correct |
7 ms |
14292 KB |
Output is correct |
15 |
Correct |
7 ms |
14320 KB |
Output is correct |
16 |
Correct |
10 ms |
14836 KB |
Output is correct |
17 |
Correct |
78 ms |
26132 KB |
Output is correct |
18 |
Correct |
6 ms |
14292 KB |
Output is correct |
19 |
Correct |
8 ms |
14292 KB |
Output is correct |
20 |
Correct |
51 ms |
19860 KB |
Output is correct |
21 |
Correct |
170 ms |
36044 KB |
Output is correct |
22 |
Correct |
162 ms |
36072 KB |
Output is correct |
23 |
Correct |
193 ms |
36120 KB |
Output is correct |
24 |
Correct |
162 ms |
36120 KB |
Output is correct |
25 |
Correct |
74 ms |
26148 KB |
Output is correct |
26 |
Correct |
74 ms |
26136 KB |
Output is correct |
27 |
Correct |
170 ms |
36120 KB |
Output is correct |
28 |
Correct |
160 ms |
36168 KB |
Output is correct |
29 |
Correct |
6 ms |
14292 KB |
Output is correct |
30 |
Correct |
6 ms |
14292 KB |
Output is correct |
31 |
Correct |
6 ms |
14292 KB |
Output is correct |
32 |
Correct |
7 ms |
14336 KB |
Output is correct |
33 |
Correct |
7 ms |
14292 KB |
Output is correct |
34 |
Correct |
7 ms |
14292 KB |
Output is correct |
35 |
Correct |
7 ms |
14292 KB |
Output is correct |
36 |
Correct |
15 ms |
15272 KB |
Output is correct |
37 |
Correct |
160 ms |
36116 KB |
Output is correct |
38 |
Correct |
6 ms |
14292 KB |
Output is correct |
39 |
Correct |
6 ms |
14292 KB |
Output is correct |
40 |
Correct |
13 ms |
15188 KB |
Output is correct |
41 |
Correct |
169 ms |
36116 KB |
Output is correct |
42 |
Correct |
6 ms |
14292 KB |
Output is correct |
43 |
Correct |
7 ms |
14292 KB |
Output is correct |
44 |
Correct |
10 ms |
14832 KB |
Output is correct |
45 |
Correct |
79 ms |
26276 KB |
Output is correct |
46 |
Correct |
6 ms |
14292 KB |
Output is correct |
47 |
Correct |
6 ms |
14292 KB |
Output is correct |
48 |
Correct |
7 ms |
14292 KB |
Output is correct |
49 |
Correct |
47 ms |
19820 KB |
Output is correct |
50 |
Correct |
162 ms |
36108 KB |
Output is correct |
51 |
Correct |
160 ms |
36136 KB |
Output is correct |
52 |
Correct |
181 ms |
36260 KB |
Output is correct |
53 |
Correct |
72 ms |
26268 KB |
Output is correct |
54 |
Correct |
73 ms |
26264 KB |
Output is correct |
55 |
Correct |
162 ms |
36136 KB |
Output is correct |
56 |
Correct |
168 ms |
36108 KB |
Output is correct |
57 |
Correct |
72 ms |
26260 KB |
Output is correct |
58 |
Correct |
7 ms |
14324 KB |
Output is correct |
59 |
Correct |
7 ms |
14292 KB |
Output is correct |
60 |
Correct |
9 ms |
14804 KB |
Output is correct |
61 |
Correct |
76 ms |
26148 KB |
Output is correct |
62 |
Correct |
6 ms |
14296 KB |
Output is correct |
63 |
Correct |
7 ms |
14292 KB |
Output is correct |
64 |
Correct |
7 ms |
14292 KB |
Output is correct |
65 |
Correct |
46 ms |
19868 KB |
Output is correct |
66 |
Correct |
74 ms |
26272 KB |
Output is correct |
67 |
Correct |
73 ms |
26268 KB |
Output is correct |
68 |
Correct |
74 ms |
26276 KB |
Output is correct |
69 |
Correct |
72 ms |
26264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
14292 KB |
Output is correct |
2 |
Correct |
6 ms |
14292 KB |
Output is correct |
3 |
Correct |
9 ms |
14356 KB |
Output is correct |
4 |
Correct |
7 ms |
14420 KB |
Output is correct |
5 |
Correct |
6 ms |
14292 KB |
Output is correct |
6 |
Correct |
13 ms |
15188 KB |
Output is correct |
7 |
Correct |
164 ms |
36124 KB |
Output is correct |
8 |
Correct |
6 ms |
14292 KB |
Output is correct |
9 |
Correct |
6 ms |
14284 KB |
Output is correct |
10 |
Correct |
6 ms |
14292 KB |
Output is correct |
11 |
Correct |
6 ms |
14312 KB |
Output is correct |
12 |
Correct |
13 ms |
15284 KB |
Output is correct |
13 |
Correct |
162 ms |
36120 KB |
Output is correct |
14 |
Correct |
7 ms |
14292 KB |
Output is correct |
15 |
Correct |
7 ms |
14320 KB |
Output is correct |
16 |
Correct |
10 ms |
14836 KB |
Output is correct |
17 |
Correct |
78 ms |
26132 KB |
Output is correct |
18 |
Correct |
6 ms |
14292 KB |
Output is correct |
19 |
Correct |
8 ms |
14292 KB |
Output is correct |
20 |
Correct |
51 ms |
19860 KB |
Output is correct |
21 |
Correct |
170 ms |
36044 KB |
Output is correct |
22 |
Correct |
162 ms |
36072 KB |
Output is correct |
23 |
Correct |
193 ms |
36120 KB |
Output is correct |
24 |
Correct |
162 ms |
36120 KB |
Output is correct |
25 |
Correct |
74 ms |
26148 KB |
Output is correct |
26 |
Correct |
74 ms |
26136 KB |
Output is correct |
27 |
Correct |
170 ms |
36120 KB |
Output is correct |
28 |
Correct |
160 ms |
36168 KB |
Output is correct |
29 |
Correct |
6 ms |
14292 KB |
Output is correct |
30 |
Correct |
6 ms |
14292 KB |
Output is correct |
31 |
Correct |
6 ms |
14292 KB |
Output is correct |
32 |
Correct |
7 ms |
14336 KB |
Output is correct |
33 |
Correct |
7 ms |
14292 KB |
Output is correct |
34 |
Correct |
7 ms |
14292 KB |
Output is correct |
35 |
Correct |
7 ms |
14292 KB |
Output is correct |
36 |
Correct |
15 ms |
15272 KB |
Output is correct |
37 |
Correct |
160 ms |
36116 KB |
Output is correct |
38 |
Correct |
6 ms |
14292 KB |
Output is correct |
39 |
Correct |
6 ms |
14292 KB |
Output is correct |
40 |
Correct |
13 ms |
15188 KB |
Output is correct |
41 |
Correct |
169 ms |
36116 KB |
Output is correct |
42 |
Correct |
6 ms |
14292 KB |
Output is correct |
43 |
Correct |
7 ms |
14292 KB |
Output is correct |
44 |
Correct |
10 ms |
14832 KB |
Output is correct |
45 |
Correct |
79 ms |
26276 KB |
Output is correct |
46 |
Correct |
6 ms |
14292 KB |
Output is correct |
47 |
Correct |
6 ms |
14292 KB |
Output is correct |
48 |
Correct |
7 ms |
14292 KB |
Output is correct |
49 |
Correct |
47 ms |
19820 KB |
Output is correct |
50 |
Correct |
162 ms |
36108 KB |
Output is correct |
51 |
Correct |
160 ms |
36136 KB |
Output is correct |
52 |
Correct |
181 ms |
36260 KB |
Output is correct |
53 |
Correct |
72 ms |
26268 KB |
Output is correct |
54 |
Correct |
73 ms |
26264 KB |
Output is correct |
55 |
Correct |
162 ms |
36136 KB |
Output is correct |
56 |
Correct |
168 ms |
36108 KB |
Output is correct |
57 |
Correct |
72 ms |
26260 KB |
Output is correct |
58 |
Correct |
7 ms |
14352 KB |
Output is correct |
59 |
Correct |
7 ms |
14292 KB |
Output is correct |
60 |
Correct |
7 ms |
14312 KB |
Output is correct |
61 |
Correct |
46 ms |
19848 KB |
Output is correct |
62 |
Correct |
162 ms |
36152 KB |
Output is correct |
63 |
Correct |
167 ms |
36124 KB |
Output is correct |
64 |
Correct |
172 ms |
36064 KB |
Output is correct |
65 |
Correct |
7 ms |
14292 KB |
Output is correct |
66 |
Correct |
47 ms |
19872 KB |
Output is correct |
67 |
Correct |
165 ms |
36172 KB |
Output is correct |
68 |
Correct |
191 ms |
36196 KB |
Output is correct |
69 |
Correct |
170 ms |
36120 KB |
Output is correct |
70 |
Correct |
6 ms |
14292 KB |
Output is correct |
71 |
Correct |
6 ms |
14292 KB |
Output is correct |
72 |
Correct |
7 ms |
14292 KB |
Output is correct |
73 |
Correct |
50 ms |
19872 KB |
Output is correct |
74 |
Correct |
192 ms |
36120 KB |
Output is correct |
75 |
Correct |
163 ms |
36112 KB |
Output is correct |
76 |
Correct |
161 ms |
36136 KB |
Output is correct |
77 |
Correct |
162 ms |
36116 KB |
Output is correct |
78 |
Correct |
7 ms |
14324 KB |
Output is correct |
79 |
Correct |
7 ms |
14292 KB |
Output is correct |
80 |
Correct |
9 ms |
14804 KB |
Output is correct |
81 |
Correct |
76 ms |
26148 KB |
Output is correct |
82 |
Correct |
6 ms |
14296 KB |
Output is correct |
83 |
Correct |
7 ms |
14292 KB |
Output is correct |
84 |
Correct |
7 ms |
14292 KB |
Output is correct |
85 |
Correct |
46 ms |
19868 KB |
Output is correct |
86 |
Correct |
74 ms |
26272 KB |
Output is correct |
87 |
Correct |
73 ms |
26268 KB |
Output is correct |
88 |
Correct |
74 ms |
26276 KB |
Output is correct |
89 |
Correct |
72 ms |
26264 KB |
Output is correct |
90 |
Correct |
6 ms |
14292 KB |
Output is correct |
91 |
Correct |
7 ms |
14292 KB |
Output is correct |
92 |
Correct |
9 ms |
14804 KB |
Output is correct |
93 |
Correct |
74 ms |
26152 KB |
Output is correct |
94 |
Correct |
6 ms |
14292 KB |
Output is correct |
95 |
Correct |
7 ms |
14292 KB |
Output is correct |
96 |
Correct |
7 ms |
14320 KB |
Output is correct |
97 |
Correct |
24 ms |
17804 KB |
Output is correct |
98 |
Correct |
72 ms |
28164 KB |
Output is correct |
99 |
Correct |
83 ms |
28168 KB |
Output is correct |
100 |
Correct |
74 ms |
28172 KB |
Output is correct |
101 |
Correct |
72 ms |
28100 KB |
Output is correct |
102 |
Correct |
72 ms |
28112 KB |
Output is correct |
103 |
Correct |
73 ms |
28172 KB |
Output is correct |
104 |
Correct |
79 ms |
28172 KB |
Output is correct |
105 |
Correct |
76 ms |
28108 KB |
Output is correct |