#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3+10;
vector<int>adj[N],vec,vec1;
vector<vector<int>>adjans,p,vecs;
int n,vis[N],vis1[N];
void dfs(int i){
if(vis[i])
return ;
vis[i] = 1;
vec.push_back(i);
for(auto x:adj[i])
dfs(x);
}
void dfs(int i,int t){
if(vis1[i])
return ;
vis1[i] = 1;
vec1.push_back(i);
for(auto x:adj[i])
if(p[i][x]==1)
dfs(x,t);
}
bool checkallequal(vector<int>vec1){
bool ret = 1;
for(int i=0;i<vec.size();i++)
for(int j=i+1;j<vec.size();j++){
bool q = 0;
for(auto x:vec1)
q |= p[vec[i]][vec[j]]==x;
ret &= q;
}
return ret;
}
int construct(std::vector<std::vector<int>> P) {
p = P;
n = p.size();
adjans = vector<vector<int>>(n,vector<int>(n,0));
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
if(p[i][j]){
adj[i].push_back(j);
adj[j].push_back(i);
}
}
bool ans = 1;
for(int i=0;i<n;i++){
dfs(i);bool q = 1;
if(vec.size()<=1){
vec.clear();
continue;
}
vector<int>vec3;
for(auto x:vec){
dfs(x,1);
for(int i=0;i<vec1.size();i++)
for(int j=i+1;j<vec1.size();j++)
q &= p[vec1[i]][vec1[j]]==1;
vecs.push_back(vec1);
for(int j=0;j<(int)vec1.size()-1;j++){
adjans[vec1[j]][vec1[j+1]] = adjans[vec1[j+1]][vec1[j]] = 1;
assert(vec1[j]!=vec1[j+1]);
}
if(vec1.size())
vec3.push_back(x);
vec1.clear();
}
for(int j=0;j<(int)vec3.size()-1;j++){
adjans[vec3[j]][vec3[j+1]] = adjans[vec3[j+1]][vec3[j]] = 1;
assert(vec3[j]!=vec3[j+1]);
}
q &= vec3.size()!=2;
if(vec3.size()>1){
adjans[vec3[0]][vec3.back()] = adjans[vec3.back()][vec3[0]] = 1;
assert(vec[0]!=vec3.back());
}
for(int j=0;j<(int)vecs.size()-1;j++)
for(int k=j+1;k<vec.size();k++)
for(auto x:vecs[j])
for(auto y:vecs[k])
q &= p[x][y]==2;
ans &= q;
vecs.clear();
}
if(!ans)
return 0;
build(adjans);
return 1;
}
Compilation message
supertrees.cpp: In function 'bool checkallequal(std::vector<int>)':
supertrees.cpp:39:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=0;i<vec.size();i++)
| ~^~~~~~~~~~~
supertrees.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int j=i+1;j<vec.size();j++){
| ~^~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:76:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i=0;i<vec1.size();i++)
| ~^~~~~~~~~~~~
supertrees.cpp:77:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int j=i+1;j<vec1.size();j++)
| ~^~~~~~~~~~~~
supertrees.cpp:103:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int k=j+1;k<vec.size();k++)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
16 ms |
1828 KB |
Output is correct |
7 |
Correct |
837 ms |
34168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
16 ms |
1828 KB |
Output is correct |
7 |
Correct |
837 ms |
34168 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1396 KB |
Output is correct |
13 |
Correct |
263 ms |
26036 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
11 ms |
1268 KB |
Output is correct |
17 |
Correct |
753 ms |
22024 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
130 ms |
6876 KB |
Output is correct |
21 |
Correct |
811 ms |
27140 KB |
Output is correct |
22 |
Correct |
556 ms |
26132 KB |
Output is correct |
23 |
Correct |
784 ms |
30196 KB |
Output is correct |
24 |
Correct |
411 ms |
26048 KB |
Output is correct |
25 |
Correct |
642 ms |
17288 KB |
Output is correct |
26 |
Correct |
518 ms |
16188 KB |
Output is correct |
27 |
Correct |
886 ms |
32200 KB |
Output is correct |
28 |
Correct |
388 ms |
26032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
12 ms |
1356 KB |
Output is correct |
9 |
Correct |
234 ms |
26068 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
24 ms |
1820 KB |
Output is correct |
13 |
Correct |
838 ms |
34220 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
14 ms |
1256 KB |
Output is correct |
17 |
Correct |
716 ms |
21932 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
126 ms |
6824 KB |
Output is correct |
22 |
Correct |
816 ms |
27140 KB |
Output is correct |
23 |
Correct |
699 ms |
26136 KB |
Output is correct |
24 |
Correct |
806 ms |
32256 KB |
Output is correct |
25 |
Correct |
288 ms |
16240 KB |
Output is correct |
26 |
Correct |
718 ms |
17284 KB |
Output is correct |
27 |
Correct |
679 ms |
26140 KB |
Output is correct |
28 |
Correct |
814 ms |
30148 KB |
Output is correct |
29 |
Correct |
300 ms |
16236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
134 ms |
6876 KB |
Output is correct |
5 |
Correct |
880 ms |
27180 KB |
Output is correct |
6 |
Correct |
601 ms |
26116 KB |
Output is correct |
7 |
Correct |
829 ms |
30188 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
121 ms |
6880 KB |
Output is correct |
10 |
Correct |
753 ms |
27104 KB |
Output is correct |
11 |
Correct |
640 ms |
26144 KB |
Output is correct |
12 |
Correct |
879 ms |
32264 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
117 ms |
6832 KB |
Output is correct |
17 |
Correct |
874 ms |
27080 KB |
Output is correct |
18 |
Correct |
808 ms |
27096 KB |
Output is correct |
19 |
Correct |
756 ms |
26476 KB |
Output is correct |
20 |
Correct |
430 ms |
26116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
16 ms |
1828 KB |
Output is correct |
7 |
Correct |
837 ms |
34168 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1396 KB |
Output is correct |
13 |
Correct |
263 ms |
26036 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
11 ms |
1268 KB |
Output is correct |
17 |
Correct |
753 ms |
22024 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
130 ms |
6876 KB |
Output is correct |
21 |
Correct |
811 ms |
27140 KB |
Output is correct |
22 |
Correct |
556 ms |
26132 KB |
Output is correct |
23 |
Correct |
784 ms |
30196 KB |
Output is correct |
24 |
Correct |
411 ms |
26048 KB |
Output is correct |
25 |
Correct |
642 ms |
17288 KB |
Output is correct |
26 |
Correct |
518 ms |
16188 KB |
Output is correct |
27 |
Correct |
886 ms |
32200 KB |
Output is correct |
28 |
Correct |
388 ms |
26032 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
12 ms |
1356 KB |
Output is correct |
37 |
Correct |
234 ms |
26068 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
24 ms |
1820 KB |
Output is correct |
41 |
Correct |
838 ms |
34220 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
14 ms |
1256 KB |
Output is correct |
45 |
Correct |
716 ms |
21932 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
126 ms |
6824 KB |
Output is correct |
50 |
Correct |
816 ms |
27140 KB |
Output is correct |
51 |
Correct |
699 ms |
26136 KB |
Output is correct |
52 |
Correct |
806 ms |
32256 KB |
Output is correct |
53 |
Correct |
288 ms |
16240 KB |
Output is correct |
54 |
Correct |
718 ms |
17284 KB |
Output is correct |
55 |
Correct |
679 ms |
26140 KB |
Output is correct |
56 |
Correct |
814 ms |
30148 KB |
Output is correct |
57 |
Correct |
300 ms |
16236 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
12 ms |
1356 KB |
Output is correct |
61 |
Correct |
655 ms |
24976 KB |
Output is correct |
62 |
Correct |
1 ms |
332 KB |
Output is correct |
63 |
Correct |
1 ms |
332 KB |
Output is correct |
64 |
Correct |
1 ms |
332 KB |
Output is correct |
65 |
Correct |
113 ms |
6836 KB |
Output is correct |
66 |
Correct |
609 ms |
17856 KB |
Output is correct |
67 |
Correct |
637 ms |
17640 KB |
Output is correct |
68 |
Correct |
610 ms |
17040 KB |
Output is correct |
69 |
Correct |
302 ms |
16612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
16 ms |
1828 KB |
Output is correct |
7 |
Correct |
837 ms |
34168 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
10 ms |
1396 KB |
Output is correct |
13 |
Correct |
263 ms |
26036 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
11 ms |
1268 KB |
Output is correct |
17 |
Correct |
753 ms |
22024 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
130 ms |
6876 KB |
Output is correct |
21 |
Correct |
811 ms |
27140 KB |
Output is correct |
22 |
Correct |
556 ms |
26132 KB |
Output is correct |
23 |
Correct |
784 ms |
30196 KB |
Output is correct |
24 |
Correct |
411 ms |
26048 KB |
Output is correct |
25 |
Correct |
642 ms |
17288 KB |
Output is correct |
26 |
Correct |
518 ms |
16188 KB |
Output is correct |
27 |
Correct |
886 ms |
32200 KB |
Output is correct |
28 |
Correct |
388 ms |
26032 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
12 ms |
1356 KB |
Output is correct |
37 |
Correct |
234 ms |
26068 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
24 ms |
1820 KB |
Output is correct |
41 |
Correct |
838 ms |
34220 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
14 ms |
1256 KB |
Output is correct |
45 |
Correct |
716 ms |
21932 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
126 ms |
6824 KB |
Output is correct |
50 |
Correct |
816 ms |
27140 KB |
Output is correct |
51 |
Correct |
699 ms |
26136 KB |
Output is correct |
52 |
Correct |
806 ms |
32256 KB |
Output is correct |
53 |
Correct |
288 ms |
16240 KB |
Output is correct |
54 |
Correct |
718 ms |
17284 KB |
Output is correct |
55 |
Correct |
679 ms |
26140 KB |
Output is correct |
56 |
Correct |
814 ms |
30148 KB |
Output is correct |
57 |
Correct |
300 ms |
16236 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
134 ms |
6876 KB |
Output is correct |
62 |
Correct |
880 ms |
27180 KB |
Output is correct |
63 |
Correct |
601 ms |
26116 KB |
Output is correct |
64 |
Correct |
829 ms |
30188 KB |
Output is correct |
65 |
Correct |
1 ms |
332 KB |
Output is correct |
66 |
Correct |
121 ms |
6880 KB |
Output is correct |
67 |
Correct |
753 ms |
27104 KB |
Output is correct |
68 |
Correct |
640 ms |
26144 KB |
Output is correct |
69 |
Correct |
879 ms |
32264 KB |
Output is correct |
70 |
Correct |
1 ms |
332 KB |
Output is correct |
71 |
Correct |
1 ms |
332 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
117 ms |
6832 KB |
Output is correct |
74 |
Correct |
874 ms |
27080 KB |
Output is correct |
75 |
Correct |
808 ms |
27096 KB |
Output is correct |
76 |
Correct |
756 ms |
26476 KB |
Output is correct |
77 |
Correct |
430 ms |
26116 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
1 ms |
332 KB |
Output is correct |
80 |
Correct |
12 ms |
1356 KB |
Output is correct |
81 |
Correct |
655 ms |
24976 KB |
Output is correct |
82 |
Correct |
1 ms |
332 KB |
Output is correct |
83 |
Correct |
1 ms |
332 KB |
Output is correct |
84 |
Correct |
1 ms |
332 KB |
Output is correct |
85 |
Correct |
113 ms |
6836 KB |
Output is correct |
86 |
Correct |
609 ms |
17856 KB |
Output is correct |
87 |
Correct |
637 ms |
17640 KB |
Output is correct |
88 |
Correct |
610 ms |
17040 KB |
Output is correct |
89 |
Correct |
302 ms |
16612 KB |
Output is correct |
90 |
Correct |
1 ms |
332 KB |
Output is correct |
91 |
Correct |
1 ms |
332 KB |
Output is correct |
92 |
Correct |
13 ms |
1504 KB |
Output is correct |
93 |
Correct |
654 ms |
25276 KB |
Output is correct |
94 |
Correct |
1 ms |
340 KB |
Output is correct |
95 |
Correct |
1 ms |
336 KB |
Output is correct |
96 |
Correct |
1 ms |
332 KB |
Output is correct |
97 |
Correct |
79 ms |
4764 KB |
Output is correct |
98 |
Correct |
721 ms |
17644 KB |
Output is correct |
99 |
Correct |
659 ms |
17644 KB |
Output is correct |
100 |
Correct |
614 ms |
17012 KB |
Output is correct |
101 |
Correct |
289 ms |
16536 KB |
Output is correct |
102 |
Correct |
633 ms |
24736 KB |
Output is correct |
103 |
Correct |
692 ms |
24740 KB |
Output is correct |
104 |
Correct |
694 ms |
24772 KB |
Output is correct |
105 |
Correct |
659 ms |
22376 KB |
Output is correct |