#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> ans;
vector<int> adj[1005];
set<int> adj2[1005];
int pa[1005],pa2[1005];
int np[1005][1005];
bool vis[1005];
int fp(int u){
if(pa[u]==u)return u;
return pa[u]=fp(pa[u]);
}
void dfs(int u,int r){
vis[u]=1;
for(auto v:adj2[u]){
if(vis[v])continue;
pa[fp(u)]=fp(v);
ans[u][v]=ans[v][u]=1;
dfs(v,r);
return;
}
if(u!=r)ans[u][r]=ans[r][u]=1;
}
int construct(vector<vector<int>> p) {
int n = p.size();
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
ans.push_back(row);
}
iota(pa,pa+n,0);
for(int i=0;i<n;++i)for(int j=0;j<n;++j)if(p[i][j]==3)return 0;
for(int i=0;i<n;++i)for(int j=0;j<n;++j)if(p[i][j]==1)pa[fp(i)]=fp(j);
for(int i=0;i<n;++i)adj[fp(i)].emplace_back(i);
for(int i=0;i<n;++i)for(auto j:adj[i])if(i!=j)ans[i][j]=ans[j][i]=1;
for(int i=0;i<n;++i)pa2[i]=pa[i];
for(int i=0;i<n;++i){
int cnt=0;
for(int j=0;j<n;++j)if(p[i][j]==2){
++cnt;
adj2[pa2[i]].insert(pa2[j]);
adj2[pa2[j]].insert(pa2[i]);
}
if(cnt==1)return 0;
}
for(int i=0;i<n;++i)if(i==pa2[i])if(!vis[i])dfs(i,i);
for(int i=0;i<n;++i)fp(i);
for(int i=0;i<n;++i)for(int j=0;j<n;++j)if(ans[i][j]==1)np[pa[i]][pa[j]]=1;
for(int i=0;i<n;++i)for(int j=0;j<n;++j){
if(i==j)continue;
if(pa[i]==pa[j]&&p[i][j]==0)return 0;
if(pa2[i]==pa2[j]&&p[i][j]!=1)return 0;
if(pa[i]==pa[j]&&pa2[i]!=pa2[j]&&p[i][j]!=2)return 0;
if(pa[i]!=pa[j]&&p[i][j]!=0)return 0;
if(np[pa[i]][pa[j]]==1&&p[i][j]==0)return 0;
if(np[pa[i]][pa[j]]==0&&p[i][j]!=0)return 0;
}
build(ans);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
9 ms |
1236 KB |
Output is correct |
7 |
Correct |
194 ms |
22112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
9 ms |
1236 KB |
Output is correct |
7 |
Correct |
194 ms |
22112 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
172 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
852 KB |
Output is correct |
17 |
Correct |
97 ms |
12128 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
43 ms |
5924 KB |
Output is correct |
21 |
Correct |
176 ms |
22112 KB |
Output is correct |
22 |
Correct |
174 ms |
23636 KB |
Output is correct |
23 |
Correct |
193 ms |
22100 KB |
Output is correct |
24 |
Correct |
179 ms |
22096 KB |
Output is correct |
25 |
Correct |
75 ms |
12244 KB |
Output is correct |
26 |
Correct |
74 ms |
13772 KB |
Output is correct |
27 |
Correct |
189 ms |
22096 KB |
Output is correct |
28 |
Correct |
170 ms |
22168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
8 ms |
1236 KB |
Output is correct |
9 |
Correct |
174 ms |
22100 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
380 KB |
Output is correct |
12 |
Correct |
14 ms |
3156 KB |
Output is correct |
13 |
Correct |
591 ms |
71084 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
9 ms |
1876 KB |
Output is correct |
17 |
Correct |
317 ms |
37628 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
48 ms |
6772 KB |
Output is correct |
22 |
Correct |
209 ms |
28740 KB |
Output is correct |
23 |
Correct |
173 ms |
25024 KB |
Output is correct |
24 |
Correct |
344 ms |
47448 KB |
Output is correct |
25 |
Correct |
73 ms |
14148 KB |
Output is correct |
26 |
Correct |
100 ms |
18884 KB |
Output is correct |
27 |
Correct |
178 ms |
25056 KB |
Output is correct |
28 |
Correct |
347 ms |
47432 KB |
Output is correct |
29 |
Correct |
80 ms |
14156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
46 ms |
5884 KB |
Output is correct |
5 |
Correct |
185 ms |
22100 KB |
Output is correct |
6 |
Correct |
174 ms |
23668 KB |
Output is correct |
7 |
Correct |
208 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
48 ms |
6708 KB |
Output is correct |
10 |
Correct |
202 ms |
28728 KB |
Output is correct |
11 |
Correct |
186 ms |
25032 KB |
Output is correct |
12 |
Correct |
322 ms |
47556 KB |
Output is correct |
13 |
Correct |
1 ms |
380 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
376 KB |
Output is correct |
16 |
Correct |
45 ms |
6656 KB |
Output is correct |
17 |
Correct |
191 ms |
28788 KB |
Output is correct |
18 |
Correct |
197 ms |
26012 KB |
Output is correct |
19 |
Correct |
176 ms |
25028 KB |
Output is correct |
20 |
Correct |
176 ms |
24060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
9 ms |
1236 KB |
Output is correct |
7 |
Correct |
194 ms |
22112 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
172 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
852 KB |
Output is correct |
17 |
Correct |
97 ms |
12128 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
43 ms |
5924 KB |
Output is correct |
21 |
Correct |
176 ms |
22112 KB |
Output is correct |
22 |
Correct |
174 ms |
23636 KB |
Output is correct |
23 |
Correct |
193 ms |
22100 KB |
Output is correct |
24 |
Correct |
179 ms |
22096 KB |
Output is correct |
25 |
Correct |
75 ms |
12244 KB |
Output is correct |
26 |
Correct |
74 ms |
13772 KB |
Output is correct |
27 |
Correct |
189 ms |
22096 KB |
Output is correct |
28 |
Correct |
170 ms |
22168 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
8 ms |
1236 KB |
Output is correct |
37 |
Correct |
174 ms |
22100 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
380 KB |
Output is correct |
40 |
Correct |
14 ms |
3156 KB |
Output is correct |
41 |
Correct |
591 ms |
71084 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
9 ms |
1876 KB |
Output is correct |
45 |
Correct |
317 ms |
37628 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
48 ms |
6772 KB |
Output is correct |
50 |
Correct |
209 ms |
28740 KB |
Output is correct |
51 |
Correct |
173 ms |
25024 KB |
Output is correct |
52 |
Correct |
344 ms |
47448 KB |
Output is correct |
53 |
Correct |
73 ms |
14148 KB |
Output is correct |
54 |
Correct |
100 ms |
18884 KB |
Output is correct |
55 |
Correct |
178 ms |
25056 KB |
Output is correct |
56 |
Correct |
347 ms |
47432 KB |
Output is correct |
57 |
Correct |
80 ms |
14156 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
4 ms |
960 KB |
Output is correct |
61 |
Correct |
102 ms |
14312 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
52 ms |
6604 KB |
Output is correct |
66 |
Correct |
96 ms |
18884 KB |
Output is correct |
67 |
Correct |
87 ms |
16328 KB |
Output is correct |
68 |
Correct |
77 ms |
15052 KB |
Output is correct |
69 |
Correct |
72 ms |
14156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
9 ms |
1236 KB |
Output is correct |
7 |
Correct |
194 ms |
22112 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1236 KB |
Output is correct |
13 |
Correct |
172 ms |
22096 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
852 KB |
Output is correct |
17 |
Correct |
97 ms |
12128 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
43 ms |
5924 KB |
Output is correct |
21 |
Correct |
176 ms |
22112 KB |
Output is correct |
22 |
Correct |
174 ms |
23636 KB |
Output is correct |
23 |
Correct |
193 ms |
22100 KB |
Output is correct |
24 |
Correct |
179 ms |
22096 KB |
Output is correct |
25 |
Correct |
75 ms |
12244 KB |
Output is correct |
26 |
Correct |
74 ms |
13772 KB |
Output is correct |
27 |
Correct |
189 ms |
22096 KB |
Output is correct |
28 |
Correct |
170 ms |
22168 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
8 ms |
1236 KB |
Output is correct |
37 |
Correct |
174 ms |
22100 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
380 KB |
Output is correct |
40 |
Correct |
14 ms |
3156 KB |
Output is correct |
41 |
Correct |
591 ms |
71084 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
9 ms |
1876 KB |
Output is correct |
45 |
Correct |
317 ms |
37628 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
48 ms |
6772 KB |
Output is correct |
50 |
Correct |
209 ms |
28740 KB |
Output is correct |
51 |
Correct |
173 ms |
25024 KB |
Output is correct |
52 |
Correct |
344 ms |
47448 KB |
Output is correct |
53 |
Correct |
73 ms |
14148 KB |
Output is correct |
54 |
Correct |
100 ms |
18884 KB |
Output is correct |
55 |
Correct |
178 ms |
25056 KB |
Output is correct |
56 |
Correct |
347 ms |
47432 KB |
Output is correct |
57 |
Correct |
80 ms |
14156 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
0 ms |
340 KB |
Output is correct |
61 |
Correct |
46 ms |
5884 KB |
Output is correct |
62 |
Correct |
185 ms |
22100 KB |
Output is correct |
63 |
Correct |
174 ms |
23668 KB |
Output is correct |
64 |
Correct |
208 ms |
22100 KB |
Output is correct |
65 |
Correct |
0 ms |
340 KB |
Output is correct |
66 |
Correct |
48 ms |
6708 KB |
Output is correct |
67 |
Correct |
202 ms |
28728 KB |
Output is correct |
68 |
Correct |
186 ms |
25032 KB |
Output is correct |
69 |
Correct |
322 ms |
47556 KB |
Output is correct |
70 |
Correct |
1 ms |
380 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
376 KB |
Output is correct |
73 |
Correct |
45 ms |
6656 KB |
Output is correct |
74 |
Correct |
191 ms |
28788 KB |
Output is correct |
75 |
Correct |
197 ms |
26012 KB |
Output is correct |
76 |
Correct |
176 ms |
25028 KB |
Output is correct |
77 |
Correct |
176 ms |
24060 KB |
Output is correct |
78 |
Correct |
1 ms |
340 KB |
Output is correct |
79 |
Correct |
0 ms |
340 KB |
Output is correct |
80 |
Correct |
4 ms |
960 KB |
Output is correct |
81 |
Correct |
102 ms |
14312 KB |
Output is correct |
82 |
Correct |
1 ms |
340 KB |
Output is correct |
83 |
Correct |
1 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
340 KB |
Output is correct |
85 |
Correct |
52 ms |
6604 KB |
Output is correct |
86 |
Correct |
96 ms |
18884 KB |
Output is correct |
87 |
Correct |
87 ms |
16328 KB |
Output is correct |
88 |
Correct |
77 ms |
15052 KB |
Output is correct |
89 |
Correct |
72 ms |
14156 KB |
Output is correct |
90 |
Correct |
0 ms |
340 KB |
Output is correct |
91 |
Correct |
1 ms |
340 KB |
Output is correct |
92 |
Correct |
4 ms |
904 KB |
Output is correct |
93 |
Correct |
90 ms |
14160 KB |
Output is correct |
94 |
Correct |
1 ms |
340 KB |
Output is correct |
95 |
Correct |
1 ms |
340 KB |
Output is correct |
96 |
Correct |
1 ms |
340 KB |
Output is correct |
97 |
Correct |
18 ms |
3844 KB |
Output is correct |
98 |
Correct |
74 ms |
14152 KB |
Output is correct |
99 |
Correct |
78 ms |
14140 KB |
Output is correct |
100 |
Correct |
100 ms |
14072 KB |
Output is correct |
101 |
Correct |
71 ms |
14148 KB |
Output is correct |
102 |
Correct |
78 ms |
14148 KB |
Output is correct |
103 |
Correct |
77 ms |
14084 KB |
Output is correct |
104 |
Correct |
78 ms |
14152 KB |
Output is correct |
105 |
Correct |
80 ms |
14156 KB |
Output is correct |