#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
int par[N],sz[N],a[N][N],ans[N][N],type[N],k,i,n,u,v,x,y,fix[N],cycle[N];
vector<int> comp[N],V[N],E;
vector<vector<int> > answer;
int find_parent(int u){
if(par[u]==u) return u;
return par[u]=find_parent(par[u]);
}
void merge(int u,int v){
u=find_parent(u);
v=find_parent(v);
if(u==v) return;
if(sz[u]<sz[v]) swap(u,v);
par[v]=u;
sz[u]+=sz[v];
}
void Go(int u){
for(k=0;k<comp[u].size();k++){
for(i=k+1;i<comp[u].size();i++){
int x=comp[u][k];
int y=comp[u][i];
if(a[x][y]==1){
V[x].push_back(y);
V[y].push_back(x); }
}
}
E.clear();
for(k=0;k<comp[u].size();k++){
x=comp[u][k];
if(fix[x]) continue;
E.push_back(x);
type[x]=1;
if(!fix[x]){
for(i=0;i<V[x].size();i++){
fix[V[x][i]]=x;
ans[x][V[x][i]]=ans[V[x][i]][x]=1;
}
}
}
if(E.size()>1){
for(k=0;k<E.size();k++){
ans[E[k]][E[(k+1)%E.size()]]=ans[E[(k+1)%E.size()]][E[k]]=1;
}
}
}
bool check(){
for(k=1;k<=n;k++){
std::vector<int> row;
for(i=1;i<=n;i++){
if(i==k) ans[k][i]=0;
else {
int x=find_parent(k);
int y=find_parent(i);
if(a[k][i]==0 && x==y)return 0;
if(!type[k] && !type[i] && a[k][i]==2 && fix[k]==fix[i]) return 0;
}
row.push_back(ans[k][i]);
}answer.push_back(row);
}
return 1;
}
int construct(std::vector<std::vector<int> > v){
//[[1, 1, 2, 2], [1, 1, 2, 2], [2, 2, 1, 2], [2, 2, 2, 1]]
n=v.size();
for(k=1;k<=n;k++)
par[k]=k,sz[k]=1;
for(k=1;k<=n;k++){
for(i=1;i<=n;i++){
a[k][i]=v[k-1][i-1];
// cout<<a[k][i]<<" ";
if(a[k][i]==3) {
return 0;
}
if(a[k][i]!=0) merge(k,i);
}
// cout<<endl;
}
for(k=1;k<=n;k++){
comp[find_parent(k)].push_back(k);
}
for(int k=1;k<=n;k++){
Go(k);
if(E.size()==2 && a[E[0]][E[1]]==2) return 0;
}
if(!check()) return 0;
build(answer);
return 1;
}
Compilation message
supertrees.cpp: In function 'void Go(int)':
supertrees.cpp:21:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(k=0;k<comp[u].size();k++){
| ~^~~~~~~~~~~~~~~
supertrees.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(i=k+1;i<comp[u].size();i++){
| ~^~~~~~~~~~~~~~~
supertrees.cpp:31:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(k=0;k<comp[u].size();k++){
| ~^~~~~~~~~~~~~~~
supertrees.cpp:37:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(i=0;i<V[x].size();i++){
| ~^~~~~~~~~~~~
supertrees.cpp:44:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(k=0;k<E.size();k++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
13 ms |
3072 KB |
Output is correct |
7 |
Correct |
279 ms |
34172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
13 ms |
3072 KB |
Output is correct |
7 |
Correct |
279 ms |
34172 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
12 ms |
2816 KB |
Output is correct |
13 |
Correct |
248 ms |
30072 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
7 ms |
2432 KB |
Output is correct |
17 |
Correct |
132 ms |
18984 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
9848 KB |
Output is correct |
21 |
Correct |
259 ms |
30584 KB |
Output is correct |
22 |
Correct |
253 ms |
30072 KB |
Output is correct |
23 |
Correct |
280 ms |
32120 KB |
Output is correct |
24 |
Correct |
249 ms |
30072 KB |
Output is correct |
25 |
Correct |
111 ms |
16760 KB |
Output is correct |
26 |
Correct |
108 ms |
15884 KB |
Output is correct |
27 |
Correct |
281 ms |
33144 KB |
Output is correct |
28 |
Correct |
251 ms |
30200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
11 ms |
2816 KB |
Output is correct |
9 |
Correct |
254 ms |
30072 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
12 ms |
2816 KB |
Output is correct |
13 |
Correct |
265 ms |
30072 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
6 ms |
2304 KB |
Output is correct |
17 |
Correct |
122 ms |
16124 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
67 ms |
9848 KB |
Output is correct |
22 |
Correct |
274 ms |
30088 KB |
Output is correct |
23 |
Correct |
261 ms |
30200 KB |
Output is correct |
24 |
Correct |
275 ms |
30072 KB |
Output is correct |
25 |
Correct |
103 ms |
12408 KB |
Output is correct |
26 |
Correct |
110 ms |
16248 KB |
Output is correct |
27 |
Correct |
252 ms |
30044 KB |
Output is correct |
28 |
Correct |
277 ms |
30200 KB |
Output is correct |
29 |
Correct |
106 ms |
12536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
66 ms |
9848 KB |
Output is correct |
5 |
Correct |
256 ms |
30584 KB |
Output is correct |
6 |
Correct |
254 ms |
30200 KB |
Output is correct |
7 |
Correct |
283 ms |
32248 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
65 ms |
9848 KB |
Output is correct |
10 |
Correct |
265 ms |
30072 KB |
Output is correct |
11 |
Correct |
253 ms |
30072 KB |
Output is correct |
12 |
Correct |
276 ms |
30072 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
68 ms |
9848 KB |
Output is correct |
17 |
Correct |
258 ms |
30072 KB |
Output is correct |
18 |
Correct |
260 ms |
30200 KB |
Output is correct |
19 |
Correct |
257 ms |
30200 KB |
Output is correct |
20 |
Correct |
249 ms |
30072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
13 ms |
3072 KB |
Output is correct |
7 |
Correct |
279 ms |
34172 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
12 ms |
2816 KB |
Output is correct |
13 |
Correct |
248 ms |
30072 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
7 ms |
2432 KB |
Output is correct |
17 |
Correct |
132 ms |
18984 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
9848 KB |
Output is correct |
21 |
Correct |
259 ms |
30584 KB |
Output is correct |
22 |
Correct |
253 ms |
30072 KB |
Output is correct |
23 |
Correct |
280 ms |
32120 KB |
Output is correct |
24 |
Correct |
249 ms |
30072 KB |
Output is correct |
25 |
Correct |
111 ms |
16760 KB |
Output is correct |
26 |
Correct |
108 ms |
15884 KB |
Output is correct |
27 |
Correct |
281 ms |
33144 KB |
Output is correct |
28 |
Correct |
251 ms |
30200 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
11 ms |
2816 KB |
Output is correct |
37 |
Correct |
254 ms |
30072 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
12 ms |
2816 KB |
Output is correct |
41 |
Correct |
265 ms |
30072 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
6 ms |
2304 KB |
Output is correct |
45 |
Correct |
122 ms |
16124 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
0 ms |
384 KB |
Output is correct |
49 |
Correct |
67 ms |
9848 KB |
Output is correct |
50 |
Correct |
274 ms |
30088 KB |
Output is correct |
51 |
Correct |
261 ms |
30200 KB |
Output is correct |
52 |
Correct |
275 ms |
30072 KB |
Output is correct |
53 |
Correct |
103 ms |
12408 KB |
Output is correct |
54 |
Correct |
110 ms |
16248 KB |
Output is correct |
55 |
Correct |
252 ms |
30044 KB |
Output is correct |
56 |
Correct |
277 ms |
30200 KB |
Output is correct |
57 |
Correct |
106 ms |
12536 KB |
Output is correct |
58 |
Correct |
0 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
512 KB |
Output is correct |
60 |
Correct |
6 ms |
2432 KB |
Output is correct |
61 |
Correct |
129 ms |
18424 KB |
Output is correct |
62 |
Correct |
1 ms |
384 KB |
Output is correct |
63 |
Correct |
0 ms |
512 KB |
Output is correct |
64 |
Correct |
1 ms |
512 KB |
Output is correct |
65 |
Correct |
67 ms |
9848 KB |
Output is correct |
66 |
Correct |
111 ms |
16120 KB |
Output is correct |
67 |
Correct |
109 ms |
15864 KB |
Output is correct |
68 |
Correct |
108 ms |
15864 KB |
Output is correct |
69 |
Correct |
110 ms |
12280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
13 ms |
3072 KB |
Output is correct |
7 |
Correct |
279 ms |
34172 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
12 ms |
2816 KB |
Output is correct |
13 |
Correct |
248 ms |
30072 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
512 KB |
Output is correct |
16 |
Correct |
7 ms |
2432 KB |
Output is correct |
17 |
Correct |
132 ms |
18984 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
65 ms |
9848 KB |
Output is correct |
21 |
Correct |
259 ms |
30584 KB |
Output is correct |
22 |
Correct |
253 ms |
30072 KB |
Output is correct |
23 |
Correct |
280 ms |
32120 KB |
Output is correct |
24 |
Correct |
249 ms |
30072 KB |
Output is correct |
25 |
Correct |
111 ms |
16760 KB |
Output is correct |
26 |
Correct |
108 ms |
15884 KB |
Output is correct |
27 |
Correct |
281 ms |
33144 KB |
Output is correct |
28 |
Correct |
251 ms |
30200 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
0 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
11 ms |
2816 KB |
Output is correct |
37 |
Correct |
254 ms |
30072 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
12 ms |
2816 KB |
Output is correct |
41 |
Correct |
265 ms |
30072 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
6 ms |
2304 KB |
Output is correct |
45 |
Correct |
122 ms |
16124 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
0 ms |
384 KB |
Output is correct |
49 |
Correct |
67 ms |
9848 KB |
Output is correct |
50 |
Correct |
274 ms |
30088 KB |
Output is correct |
51 |
Correct |
261 ms |
30200 KB |
Output is correct |
52 |
Correct |
275 ms |
30072 KB |
Output is correct |
53 |
Correct |
103 ms |
12408 KB |
Output is correct |
54 |
Correct |
110 ms |
16248 KB |
Output is correct |
55 |
Correct |
252 ms |
30044 KB |
Output is correct |
56 |
Correct |
277 ms |
30200 KB |
Output is correct |
57 |
Correct |
106 ms |
12536 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
512 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
66 ms |
9848 KB |
Output is correct |
62 |
Correct |
256 ms |
30584 KB |
Output is correct |
63 |
Correct |
254 ms |
30200 KB |
Output is correct |
64 |
Correct |
283 ms |
32248 KB |
Output is correct |
65 |
Correct |
0 ms |
384 KB |
Output is correct |
66 |
Correct |
65 ms |
9848 KB |
Output is correct |
67 |
Correct |
265 ms |
30072 KB |
Output is correct |
68 |
Correct |
253 ms |
30072 KB |
Output is correct |
69 |
Correct |
276 ms |
30072 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
0 ms |
512 KB |
Output is correct |
72 |
Correct |
0 ms |
512 KB |
Output is correct |
73 |
Correct |
68 ms |
9848 KB |
Output is correct |
74 |
Correct |
258 ms |
30072 KB |
Output is correct |
75 |
Correct |
260 ms |
30200 KB |
Output is correct |
76 |
Correct |
257 ms |
30200 KB |
Output is correct |
77 |
Correct |
249 ms |
30072 KB |
Output is correct |
78 |
Correct |
0 ms |
384 KB |
Output is correct |
79 |
Correct |
1 ms |
512 KB |
Output is correct |
80 |
Correct |
6 ms |
2432 KB |
Output is correct |
81 |
Correct |
129 ms |
18424 KB |
Output is correct |
82 |
Correct |
1 ms |
384 KB |
Output is correct |
83 |
Correct |
0 ms |
512 KB |
Output is correct |
84 |
Correct |
1 ms |
512 KB |
Output is correct |
85 |
Correct |
67 ms |
9848 KB |
Output is correct |
86 |
Correct |
111 ms |
16120 KB |
Output is correct |
87 |
Correct |
109 ms |
15864 KB |
Output is correct |
88 |
Correct |
108 ms |
15864 KB |
Output is correct |
89 |
Correct |
110 ms |
12280 KB |
Output is correct |
90 |
Correct |
0 ms |
384 KB |
Output is correct |
91 |
Correct |
0 ms |
384 KB |
Output is correct |
92 |
Correct |
5 ms |
640 KB |
Output is correct |
93 |
Correct |
107 ms |
8440 KB |
Output is correct |
94 |
Correct |
0 ms |
384 KB |
Output is correct |
95 |
Correct |
0 ms |
384 KB |
Output is correct |
96 |
Correct |
0 ms |
384 KB |
Output is correct |
97 |
Correct |
26 ms |
2552 KB |
Output is correct |
98 |
Correct |
100 ms |
8460 KB |
Output is correct |
99 |
Correct |
101 ms |
8952 KB |
Output is correct |
100 |
Correct |
98 ms |
8568 KB |
Output is correct |
101 |
Correct |
100 ms |
9612 KB |
Output is correct |
102 |
Correct |
105 ms |
8312 KB |
Output is correct |
103 |
Correct |
105 ms |
8312 KB |
Output is correct |
104 |
Correct |
105 ms |
8336 KB |
Output is correct |
105 |
Correct |
107 ms |
8440 KB |
Output is correct |