#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
int n,m,fa[1010],d[1010];
int find(int a){
return fa[a]==a?a:fa[a]=find(fa[a]);
}
int merge(int u,int v){
u=find(u),v=find(v);
if(u==v) return false;
fa[u]=v;return true;
}
struct node{
int id,fa;
bool operator <(const node &b)const{
return fa<b.fa;
}
}c[1010];
int construct(vector<vector<int> >p){
n=p.size();
vector<vector<int> >ans;
for(int i=0;i<n;i++){
vector<int> row;
row.resize(n);
ans.push_back(row);
}
for(int i=0;i<n;i++) fa[i]=i;
for(int i=0;i<n;i++) for(int j=i+1;j<n;j++){
if(p[i][j]>=3) return false;
if(p[i][j]==1) merge(i,j);
}
for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) if(p[i][j]!=p[find(i)][find(j)]) return false;
for(int i=0;i<n;i++) fa[i]=i;
for(int i=0;i<n;i++) for(int j=i+1;j<n;j++){
if(p[i][j]==1){
if(merge(i,j)) ans[i][j]=ans[j][i]=1;
}
}
for(int i=0;i<n;i++) d[i]=find(i),fa[i]=i;
sort(d,d+n);
int sz=unique(d,d+n)-d;
for(int i=0;i<sz;i++){
for(int j=i+1;j<sz;j++){
if(p[d[i]][d[j]]==2) merge(d[i],d[j]);
}
}
for(int i=0;i<sz;i++){
for(int j=i+1;j<sz;j++){
if((p[d[i]][d[j]]==0&&find(d[i])==find(d[j]))||(p[d[i]][d[j]]==2&&find(d[i])!=find(d[j]))) return 0;
}
}
for(int i=0;i<sz;i++) c[i].id=d[i],c[i].fa=find(d[i]);
sort(c,c+sz);
for(int i=0,lst=0;i<sz;i++){
if(i&&c[i].fa==c[i-1].fa) ans[c[i].id][c[i-1].id]=ans[c[i-1].id][c[i].id]=1;
if(i&&c[i].fa!=c[i-1].fa){
if(lst!=i-1) ans[c[i-1].id][c[lst].id]=ans[c[lst].id][c[i-1].id]=1;
if(lst==i-2) return false;
lst=i;
}
if(i==sz-1){
if(lst==i-1) return false;
if(lst!=i) ans[c[i].id][c[lst].id]=ans[c[lst].id][c[i].id]=1;
}
}
build(ans);
return true;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 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 |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
265 ms |
22136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 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 |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
265 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1280 KB |
Output is correct |
13 |
Correct |
246 ms |
22264 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
122 ms |
12152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
61 ms |
5880 KB |
Output is correct |
21 |
Correct |
249 ms |
22136 KB |
Output is correct |
22 |
Correct |
245 ms |
22136 KB |
Output is correct |
23 |
Correct |
269 ms |
22264 KB |
Output is correct |
24 |
Correct |
241 ms |
22136 KB |
Output is correct |
25 |
Correct |
108 ms |
12128 KB |
Output is correct |
26 |
Correct |
109 ms |
12152 KB |
Output is correct |
27 |
Correct |
258 ms |
22136 KB |
Output is correct |
28 |
Correct |
240 ms |
22136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
11 ms |
1280 KB |
Output is correct |
9 |
Correct |
244 ms |
22136 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1280 KB |
Output is correct |
13 |
Correct |
264 ms |
22136 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
121 ms |
12128 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
61 ms |
5880 KB |
Output is correct |
22 |
Correct |
248 ms |
22136 KB |
Output is correct |
23 |
Correct |
244 ms |
22136 KB |
Output is correct |
24 |
Correct |
260 ms |
22136 KB |
Output is correct |
25 |
Correct |
108 ms |
12152 KB |
Output is correct |
26 |
Correct |
118 ms |
12152 KB |
Output is correct |
27 |
Correct |
245 ms |
22264 KB |
Output is correct |
28 |
Correct |
262 ms |
22140 KB |
Output is correct |
29 |
Correct |
109 ms |
12152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
61 ms |
5880 KB |
Output is correct |
5 |
Correct |
250 ms |
22392 KB |
Output is correct |
6 |
Correct |
242 ms |
22136 KB |
Output is correct |
7 |
Correct |
259 ms |
22136 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
63 ms |
5880 KB |
Output is correct |
10 |
Correct |
248 ms |
22140 KB |
Output is correct |
11 |
Correct |
247 ms |
22136 KB |
Output is correct |
12 |
Correct |
263 ms |
22136 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
62 ms |
5880 KB |
Output is correct |
17 |
Correct |
249 ms |
22136 KB |
Output is correct |
18 |
Correct |
249 ms |
22108 KB |
Output is correct |
19 |
Correct |
247 ms |
22136 KB |
Output is correct |
20 |
Correct |
246 ms |
22136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 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 |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
265 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1280 KB |
Output is correct |
13 |
Correct |
246 ms |
22264 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
122 ms |
12152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
61 ms |
5880 KB |
Output is correct |
21 |
Correct |
249 ms |
22136 KB |
Output is correct |
22 |
Correct |
245 ms |
22136 KB |
Output is correct |
23 |
Correct |
269 ms |
22264 KB |
Output is correct |
24 |
Correct |
241 ms |
22136 KB |
Output is correct |
25 |
Correct |
108 ms |
12128 KB |
Output is correct |
26 |
Correct |
109 ms |
12152 KB |
Output is correct |
27 |
Correct |
258 ms |
22136 KB |
Output is correct |
28 |
Correct |
240 ms |
22136 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
1 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 |
0 ms |
256 KB |
Output is correct |
36 |
Correct |
11 ms |
1280 KB |
Output is correct |
37 |
Correct |
244 ms |
22136 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
0 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1280 KB |
Output is correct |
41 |
Correct |
264 ms |
22136 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
5 ms |
768 KB |
Output is correct |
45 |
Correct |
121 ms |
12128 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
61 ms |
5880 KB |
Output is correct |
50 |
Correct |
248 ms |
22136 KB |
Output is correct |
51 |
Correct |
244 ms |
22136 KB |
Output is correct |
52 |
Correct |
260 ms |
22136 KB |
Output is correct |
53 |
Correct |
108 ms |
12152 KB |
Output is correct |
54 |
Correct |
118 ms |
12152 KB |
Output is correct |
55 |
Correct |
245 ms |
22264 KB |
Output is correct |
56 |
Correct |
262 ms |
22140 KB |
Output is correct |
57 |
Correct |
109 ms |
12152 KB |
Output is correct |
58 |
Correct |
0 ms |
256 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
8 ms |
768 KB |
Output is correct |
61 |
Correct |
148 ms |
12184 KB |
Output is correct |
62 |
Correct |
1 ms |
384 KB |
Output is correct |
63 |
Correct |
0 ms |
256 KB |
Output is correct |
64 |
Correct |
1 ms |
384 KB |
Output is correct |
65 |
Correct |
67 ms |
5880 KB |
Output is correct |
66 |
Correct |
112 ms |
12152 KB |
Output is correct |
67 |
Correct |
114 ms |
12120 KB |
Output is correct |
68 |
Correct |
110 ms |
12152 KB |
Output is correct |
69 |
Correct |
110 ms |
12152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 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 |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
265 ms |
22136 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1280 KB |
Output is correct |
13 |
Correct |
246 ms |
22264 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
122 ms |
12152 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
61 ms |
5880 KB |
Output is correct |
21 |
Correct |
249 ms |
22136 KB |
Output is correct |
22 |
Correct |
245 ms |
22136 KB |
Output is correct |
23 |
Correct |
269 ms |
22264 KB |
Output is correct |
24 |
Correct |
241 ms |
22136 KB |
Output is correct |
25 |
Correct |
108 ms |
12128 KB |
Output is correct |
26 |
Correct |
109 ms |
12152 KB |
Output is correct |
27 |
Correct |
258 ms |
22136 KB |
Output is correct |
28 |
Correct |
240 ms |
22136 KB |
Output is correct |
29 |
Correct |
0 ms |
256 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
256 KB |
Output is correct |
32 |
Correct |
1 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 |
0 ms |
256 KB |
Output is correct |
36 |
Correct |
11 ms |
1280 KB |
Output is correct |
37 |
Correct |
244 ms |
22136 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
0 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1280 KB |
Output is correct |
41 |
Correct |
264 ms |
22136 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
5 ms |
768 KB |
Output is correct |
45 |
Correct |
121 ms |
12128 KB |
Output is correct |
46 |
Correct |
0 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
61 ms |
5880 KB |
Output is correct |
50 |
Correct |
248 ms |
22136 KB |
Output is correct |
51 |
Correct |
244 ms |
22136 KB |
Output is correct |
52 |
Correct |
260 ms |
22136 KB |
Output is correct |
53 |
Correct |
108 ms |
12152 KB |
Output is correct |
54 |
Correct |
118 ms |
12152 KB |
Output is correct |
55 |
Correct |
245 ms |
22264 KB |
Output is correct |
56 |
Correct |
262 ms |
22140 KB |
Output is correct |
57 |
Correct |
109 ms |
12152 KB |
Output is correct |
58 |
Correct |
0 ms |
384 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
1 ms |
384 KB |
Output is correct |
61 |
Correct |
61 ms |
5880 KB |
Output is correct |
62 |
Correct |
250 ms |
22392 KB |
Output is correct |
63 |
Correct |
242 ms |
22136 KB |
Output is correct |
64 |
Correct |
259 ms |
22136 KB |
Output is correct |
65 |
Correct |
0 ms |
384 KB |
Output is correct |
66 |
Correct |
63 ms |
5880 KB |
Output is correct |
67 |
Correct |
248 ms |
22140 KB |
Output is correct |
68 |
Correct |
247 ms |
22136 KB |
Output is correct |
69 |
Correct |
263 ms |
22136 KB |
Output is correct |
70 |
Correct |
1 ms |
256 KB |
Output is correct |
71 |
Correct |
1 ms |
256 KB |
Output is correct |
72 |
Correct |
1 ms |
384 KB |
Output is correct |
73 |
Correct |
62 ms |
5880 KB |
Output is correct |
74 |
Correct |
249 ms |
22136 KB |
Output is correct |
75 |
Correct |
249 ms |
22108 KB |
Output is correct |
76 |
Correct |
247 ms |
22136 KB |
Output is correct |
77 |
Correct |
246 ms |
22136 KB |
Output is correct |
78 |
Correct |
0 ms |
256 KB |
Output is correct |
79 |
Correct |
0 ms |
256 KB |
Output is correct |
80 |
Correct |
8 ms |
768 KB |
Output is correct |
81 |
Correct |
148 ms |
12184 KB |
Output is correct |
82 |
Correct |
1 ms |
384 KB |
Output is correct |
83 |
Correct |
0 ms |
256 KB |
Output is correct |
84 |
Correct |
1 ms |
384 KB |
Output is correct |
85 |
Correct |
67 ms |
5880 KB |
Output is correct |
86 |
Correct |
112 ms |
12152 KB |
Output is correct |
87 |
Correct |
114 ms |
12120 KB |
Output is correct |
88 |
Correct |
110 ms |
12152 KB |
Output is correct |
89 |
Correct |
110 ms |
12152 KB |
Output is correct |
90 |
Correct |
0 ms |
256 KB |
Output is correct |
91 |
Correct |
0 ms |
256 KB |
Output is correct |
92 |
Correct |
6 ms |
768 KB |
Output is correct |
93 |
Correct |
116 ms |
12180 KB |
Output is correct |
94 |
Correct |
0 ms |
256 KB |
Output is correct |
95 |
Correct |
0 ms |
256 KB |
Output is correct |
96 |
Correct |
0 ms |
256 KB |
Output is correct |
97 |
Correct |
27 ms |
3320 KB |
Output is correct |
98 |
Correct |
116 ms |
12152 KB |
Output is correct |
99 |
Correct |
108 ms |
12152 KB |
Output is correct |
100 |
Correct |
119 ms |
12152 KB |
Output is correct |
101 |
Correct |
105 ms |
12152 KB |
Output is correct |
102 |
Correct |
116 ms |
12156 KB |
Output is correct |
103 |
Correct |
123 ms |
12152 KB |
Output is correct |
104 |
Correct |
115 ms |
12152 KB |
Output is correct |
105 |
Correct |
118 ms |
12124 KB |
Output is correct |