#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> ret;
vector<vector<int>> p;
inline void edge(int i, int j){
ret[i][j]=ret[j][i]=1;
}
bool create(vector<int> conn){
vector<int> cyc;
vector<int> fr(ret.size(),-1);
for(auto i:conn){
int from=-1;
for(auto j:cyc){
if(p[i][j]==0){
return false;
}
else if(p[i][j]==1){
if(from!=-1){
return false;
}
else{
from=j;
}
}
}
if(from==-1){
cyc.push_back(i);
fr[i]=i;
}
else{
edge(from,i);
fr[i]=from;
}
}
for(auto i:conn){
for(auto j:conn){
if(i==j){
continue;
}
if(fr[i]==fr[j]&&p[i][j]!=1||
(fr[i]!=fr[j]&&p[i][j]!=2)){
return false;
}
}
}
for(int i=0; i+1<cyc.size(); i++){
edge(cyc[i],cyc[i+1]);
}
if(cyc.size()==2){
return false;
}
if(cyc.size()>2){
edge(cyc[0],cyc.back());
}
return true;
}
int construct(std::vector<std::vector<int>> P) {
p=move(P);
int n=p.size();
vector<bool> used(n,false);
ret.assign(n,vector<int>(n,0));
for(int i=0; i<n; i++){
if(used[i]){
continue;
}
used[i]=true;
vector<int> conn;
conn.push_back(i);
for(int j=i+1; j<n; j++){
if(p[i][j]>0){
conn.push_back(j);
used[j]=true;
}
}
for(auto j:conn){
for(int k=0; k<n; k++){
if(p[i][k]==0&&p[j][k]!=0){
return 0;
}
}
}
if(!create(conn)){
return 0;
}
}
build(ret);
return 1;
// vector<vector<int>> v(P.size(),vector<int>(P.size(),0));
// for(int i=1; i<P.size(); i++){
// v[0][i]=v[i][0]=1;
// }
// build(v);
// return 1;
}
Compilation message
supertrees.cpp: In function 'bool create(std::vector<int>)':
supertrees.cpp:44:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
44 | if(fr[i]==fr[j]&&p[i][j]!=1||
supertrees.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=0; i+1<cyc.size(); i++){
| ~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
13 ms |
1100 KB |
Output is correct |
7 |
Correct |
263 ms |
22028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
13 ms |
1100 KB |
Output is correct |
7 |
Correct |
263 ms |
22028 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1100 KB |
Output is correct |
13 |
Correct |
224 ms |
21960 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
704 KB |
Output is correct |
17 |
Correct |
106 ms |
12032 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
75 ms |
6244 KB |
Output is correct |
21 |
Correct |
235 ms |
23932 KB |
Output is correct |
22 |
Correct |
244 ms |
24052 KB |
Output is correct |
23 |
Correct |
234 ms |
24004 KB |
Output is correct |
24 |
Correct |
231 ms |
23916 KB |
Output is correct |
25 |
Correct |
97 ms |
14072 KB |
Output is correct |
26 |
Correct |
106 ms |
13996 KB |
Output is correct |
27 |
Correct |
245 ms |
23892 KB |
Output is correct |
28 |
Correct |
268 ms |
23952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
280 KB |
Output is correct |
8 |
Correct |
10 ms |
1228 KB |
Output is correct |
9 |
Correct |
230 ms |
21952 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1116 KB |
Output is correct |
13 |
Correct |
245 ms |
22076 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
4 ms |
716 KB |
Output is correct |
17 |
Correct |
99 ms |
12044 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
66 ms |
5756 KB |
Output is correct |
22 |
Correct |
230 ms |
22024 KB |
Output is correct |
23 |
Correct |
231 ms |
22028 KB |
Output is correct |
24 |
Correct |
258 ms |
21960 KB |
Output is correct |
25 |
Correct |
94 ms |
12160 KB |
Output is correct |
26 |
Correct |
94 ms |
12028 KB |
Output is correct |
27 |
Correct |
257 ms |
21952 KB |
Output is correct |
28 |
Correct |
236 ms |
22020 KB |
Output is correct |
29 |
Correct |
115 ms |
12028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
59 ms |
5756 KB |
Output is correct |
5 |
Correct |
226 ms |
21956 KB |
Output is correct |
6 |
Correct |
234 ms |
21984 KB |
Output is correct |
7 |
Correct |
273 ms |
21956 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
67 ms |
5760 KB |
Output is correct |
10 |
Correct |
236 ms |
22020 KB |
Output is correct |
11 |
Correct |
233 ms |
21976 KB |
Output is correct |
12 |
Correct |
244 ms |
21928 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
57 ms |
5732 KB |
Output is correct |
17 |
Correct |
227 ms |
22040 KB |
Output is correct |
18 |
Correct |
228 ms |
22012 KB |
Output is correct |
19 |
Correct |
253 ms |
22012 KB |
Output is correct |
20 |
Correct |
227 ms |
22028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
13 ms |
1100 KB |
Output is correct |
7 |
Correct |
263 ms |
22028 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1100 KB |
Output is correct |
13 |
Correct |
224 ms |
21960 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
704 KB |
Output is correct |
17 |
Correct |
106 ms |
12032 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
75 ms |
6244 KB |
Output is correct |
21 |
Correct |
235 ms |
23932 KB |
Output is correct |
22 |
Correct |
244 ms |
24052 KB |
Output is correct |
23 |
Correct |
234 ms |
24004 KB |
Output is correct |
24 |
Correct |
231 ms |
23916 KB |
Output is correct |
25 |
Correct |
97 ms |
14072 KB |
Output is correct |
26 |
Correct |
106 ms |
13996 KB |
Output is correct |
27 |
Correct |
245 ms |
23892 KB |
Output is correct |
28 |
Correct |
268 ms |
23952 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
280 KB |
Output is correct |
36 |
Correct |
10 ms |
1228 KB |
Output is correct |
37 |
Correct |
230 ms |
21952 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1116 KB |
Output is correct |
41 |
Correct |
245 ms |
22076 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
4 ms |
716 KB |
Output is correct |
45 |
Correct |
99 ms |
12044 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
66 ms |
5756 KB |
Output is correct |
50 |
Correct |
230 ms |
22024 KB |
Output is correct |
51 |
Correct |
231 ms |
22028 KB |
Output is correct |
52 |
Correct |
258 ms |
21960 KB |
Output is correct |
53 |
Correct |
94 ms |
12160 KB |
Output is correct |
54 |
Correct |
94 ms |
12028 KB |
Output is correct |
55 |
Correct |
257 ms |
21952 KB |
Output is correct |
56 |
Correct |
236 ms |
22020 KB |
Output is correct |
57 |
Correct |
115 ms |
12028 KB |
Output is correct |
58 |
Correct |
1 ms |
316 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
8 ms |
844 KB |
Output is correct |
61 |
Correct |
101 ms |
14020 KB |
Output is correct |
62 |
Correct |
1 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
204 KB |
Output is correct |
64 |
Correct |
1 ms |
204 KB |
Output is correct |
65 |
Correct |
58 ms |
6240 KB |
Output is correct |
66 |
Correct |
99 ms |
14068 KB |
Output is correct |
67 |
Correct |
126 ms |
14128 KB |
Output is correct |
68 |
Correct |
93 ms |
14012 KB |
Output is correct |
69 |
Correct |
95 ms |
14072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
13 ms |
1100 KB |
Output is correct |
7 |
Correct |
263 ms |
22028 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1100 KB |
Output is correct |
13 |
Correct |
224 ms |
21960 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
5 ms |
704 KB |
Output is correct |
17 |
Correct |
106 ms |
12032 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
75 ms |
6244 KB |
Output is correct |
21 |
Correct |
235 ms |
23932 KB |
Output is correct |
22 |
Correct |
244 ms |
24052 KB |
Output is correct |
23 |
Correct |
234 ms |
24004 KB |
Output is correct |
24 |
Correct |
231 ms |
23916 KB |
Output is correct |
25 |
Correct |
97 ms |
14072 KB |
Output is correct |
26 |
Correct |
106 ms |
13996 KB |
Output is correct |
27 |
Correct |
245 ms |
23892 KB |
Output is correct |
28 |
Correct |
268 ms |
23952 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
280 KB |
Output is correct |
36 |
Correct |
10 ms |
1228 KB |
Output is correct |
37 |
Correct |
230 ms |
21952 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1116 KB |
Output is correct |
41 |
Correct |
245 ms |
22076 KB |
Output is correct |
42 |
Correct |
1 ms |
204 KB |
Output is correct |
43 |
Correct |
1 ms |
204 KB |
Output is correct |
44 |
Correct |
4 ms |
716 KB |
Output is correct |
45 |
Correct |
99 ms |
12044 KB |
Output is correct |
46 |
Correct |
1 ms |
204 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
1 ms |
204 KB |
Output is correct |
49 |
Correct |
66 ms |
5756 KB |
Output is correct |
50 |
Correct |
230 ms |
22024 KB |
Output is correct |
51 |
Correct |
231 ms |
22028 KB |
Output is correct |
52 |
Correct |
258 ms |
21960 KB |
Output is correct |
53 |
Correct |
94 ms |
12160 KB |
Output is correct |
54 |
Correct |
94 ms |
12028 KB |
Output is correct |
55 |
Correct |
257 ms |
21952 KB |
Output is correct |
56 |
Correct |
236 ms |
22020 KB |
Output is correct |
57 |
Correct |
115 ms |
12028 KB |
Output is correct |
58 |
Correct |
1 ms |
204 KB |
Output is correct |
59 |
Correct |
1 ms |
204 KB |
Output is correct |
60 |
Correct |
1 ms |
204 KB |
Output is correct |
61 |
Correct |
59 ms |
5756 KB |
Output is correct |
62 |
Correct |
226 ms |
21956 KB |
Output is correct |
63 |
Correct |
234 ms |
21984 KB |
Output is correct |
64 |
Correct |
273 ms |
21956 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
67 ms |
5760 KB |
Output is correct |
67 |
Correct |
236 ms |
22020 KB |
Output is correct |
68 |
Correct |
233 ms |
21976 KB |
Output is correct |
69 |
Correct |
244 ms |
21928 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
0 ms |
204 KB |
Output is correct |
73 |
Correct |
57 ms |
5732 KB |
Output is correct |
74 |
Correct |
227 ms |
22040 KB |
Output is correct |
75 |
Correct |
228 ms |
22012 KB |
Output is correct |
76 |
Correct |
253 ms |
22012 KB |
Output is correct |
77 |
Correct |
227 ms |
22028 KB |
Output is correct |
78 |
Correct |
1 ms |
316 KB |
Output is correct |
79 |
Correct |
1 ms |
204 KB |
Output is correct |
80 |
Correct |
8 ms |
844 KB |
Output is correct |
81 |
Correct |
101 ms |
14020 KB |
Output is correct |
82 |
Correct |
1 ms |
204 KB |
Output is correct |
83 |
Correct |
1 ms |
204 KB |
Output is correct |
84 |
Correct |
1 ms |
204 KB |
Output is correct |
85 |
Correct |
58 ms |
6240 KB |
Output is correct |
86 |
Correct |
99 ms |
14068 KB |
Output is correct |
87 |
Correct |
126 ms |
14128 KB |
Output is correct |
88 |
Correct |
93 ms |
14012 KB |
Output is correct |
89 |
Correct |
95 ms |
14072 KB |
Output is correct |
90 |
Correct |
1 ms |
204 KB |
Output is correct |
91 |
Correct |
1 ms |
204 KB |
Output is correct |
92 |
Correct |
5 ms |
788 KB |
Output is correct |
93 |
Correct |
123 ms |
13984 KB |
Output is correct |
94 |
Correct |
1 ms |
204 KB |
Output is correct |
95 |
Correct |
1 ms |
204 KB |
Output is correct |
96 |
Correct |
1 ms |
204 KB |
Output is correct |
97 |
Correct |
30 ms |
3688 KB |
Output is correct |
98 |
Correct |
97 ms |
14056 KB |
Output is correct |
99 |
Correct |
119 ms |
14056 KB |
Output is correct |
100 |
Correct |
99 ms |
14060 KB |
Output is correct |
101 |
Correct |
96 ms |
14076 KB |
Output is correct |
102 |
Correct |
98 ms |
14020 KB |
Output is correct |
103 |
Correct |
101 ms |
14184 KB |
Output is correct |
104 |
Correct |
94 ms |
14072 KB |
Output is correct |
105 |
Correct |
100 ms |
14060 KB |
Output is correct |