#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int parent[1001];
int find(int x) {
if(parent[x]<0) return x;
return parent[x]=find(parent[x]);
}
void merge(int x, int y) {
x=find(x), y=find(y);
if(x==y) return;
if(parent[x]>parent[y]) swap(x, y);
parent[x]+=parent[y];
parent[y]=x;
}
vector<int> adj[1001], cc[1001], root;
vector<vector<int>> ans;
bool visited[1001];
int construct(vector<vector<int>> p) {
int n = p.size();
ans.resize(n);
for(int i=0; i<n; i++) {
ans[i].resize(n);
for(int j=0; j<n; j++) ans[i][j]=0;
}
for(int i=0; i<n; i++) {
if(p[i][i]!=1) return 0;
for(int j=0; j<n; j++) if(p[i][j]!=p[j][i] || p[i][j]==3) return 0;
}
memset(parent, -1, sizeof(parent));
for(int i=0; i<n; i++) for(int j=i+1; j<n; j++) if(p[i][j]) merge(i, j);
for(int i=0; i<n; i++) root.push_back(find(i));
sort(root.begin(), root.end());
root.erase(unique(root.begin(), root.end()), root.end());
vector<int> v;
for(int i=0; i<(int)root.size(); i++) {
for(int j=0; j<n; j++) if(find(j)==root[i]) cc[i].push_back(j);
for(auto j: cc[i]) {
for(auto k: cc[i]) if(j!=k) {
if(!p[j][k]) return 0;
if(p[j][k]==1) adj[j].push_back(k);
}
if(!visited[j]) {
v.push_back(j);
for(auto k: adj[j]) visited[k]=1;
}
}
if(v.size()==2) return 0;
for(auto j: v) for(auto k: v) if(j<k) {
for(auto l: adj[j]) for(auto m: adj[k]) if(l==m || p[l][m]==1) return 0;
}
for(auto j: v) for(auto l: adj[j]) for(auto k: adj[j]) if(p[k][l]==2) return 0;
for(auto j: v) for(auto k: adj[j]) ans[j][k]=ans[k][j]=1;
if(v.size()>2) for(int j=0; j<(int)v.size(); j++) {
int a=v[j], b=(j?v[j-1]:v.back());
ans[a][b]=ans[b][a]=1;
}
v.clear();
memset(visited, 0, sizeof(visited));
}
build(ans);
return 1;
}
# |
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 |
1 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 |
7 ms |
1428 KB |
Output is correct |
7 |
Correct |
174 ms |
26056 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 |
1 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 |
7 ms |
1428 KB |
Output is correct |
7 |
Correct |
174 ms |
26056 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1208 KB |
Output is correct |
13 |
Correct |
168 ms |
22076 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
85 ms |
12108 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
42 ms |
5840 KB |
Output is correct |
21 |
Correct |
171 ms |
22604 KB |
Output is correct |
22 |
Correct |
166 ms |
22136 KB |
Output is correct |
23 |
Correct |
179 ms |
24140 KB |
Output is correct |
24 |
Correct |
169 ms |
22072 KB |
Output is correct |
25 |
Correct |
78 ms |
12344 KB |
Output is correct |
26 |
Correct |
76 ms |
12100 KB |
Output is correct |
27 |
Correct |
174 ms |
25036 KB |
Output is correct |
28 |
Correct |
168 ms |
22084 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 |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
7 ms |
1236 KB |
Output is correct |
9 |
Correct |
170 ms |
22080 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
177 ms |
22080 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
86 ms |
12084 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
42 ms |
5732 KB |
Output is correct |
22 |
Correct |
172 ms |
22348 KB |
Output is correct |
23 |
Correct |
166 ms |
22072 KB |
Output is correct |
24 |
Correct |
176 ms |
22096 KB |
Output is correct |
25 |
Correct |
78 ms |
12096 KB |
Output is correct |
26 |
Correct |
78 ms |
12108 KB |
Output is correct |
27 |
Correct |
166 ms |
22072 KB |
Output is correct |
28 |
Correct |
178 ms |
22112 KB |
Output is correct |
29 |
Correct |
77 ms |
12084 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 |
51 ms |
5808 KB |
Output is correct |
5 |
Correct |
171 ms |
22584 KB |
Output is correct |
6 |
Correct |
168 ms |
22092 KB |
Output is correct |
7 |
Correct |
182 ms |
24116 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
42 ms |
5800 KB |
Output is correct |
10 |
Correct |
168 ms |
22076 KB |
Output is correct |
11 |
Correct |
173 ms |
22092 KB |
Output is correct |
12 |
Correct |
173 ms |
22068 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
42 ms |
5820 KB |
Output is correct |
17 |
Correct |
168 ms |
22072 KB |
Output is correct |
18 |
Correct |
169 ms |
22100 KB |
Output is correct |
19 |
Correct |
173 ms |
22076 KB |
Output is correct |
20 |
Correct |
169 ms |
22084 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 |
1 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 |
7 ms |
1428 KB |
Output is correct |
7 |
Correct |
174 ms |
26056 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1208 KB |
Output is correct |
13 |
Correct |
168 ms |
22076 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
85 ms |
12108 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
42 ms |
5840 KB |
Output is correct |
21 |
Correct |
171 ms |
22604 KB |
Output is correct |
22 |
Correct |
166 ms |
22136 KB |
Output is correct |
23 |
Correct |
179 ms |
24140 KB |
Output is correct |
24 |
Correct |
169 ms |
22072 KB |
Output is correct |
25 |
Correct |
78 ms |
12344 KB |
Output is correct |
26 |
Correct |
76 ms |
12100 KB |
Output is correct |
27 |
Correct |
174 ms |
25036 KB |
Output is correct |
28 |
Correct |
168 ms |
22084 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
170 ms |
22080 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
177 ms |
22080 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
86 ms |
12084 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
42 ms |
5732 KB |
Output is correct |
50 |
Correct |
172 ms |
22348 KB |
Output is correct |
51 |
Correct |
166 ms |
22072 KB |
Output is correct |
52 |
Correct |
176 ms |
22096 KB |
Output is correct |
53 |
Correct |
78 ms |
12096 KB |
Output is correct |
54 |
Correct |
78 ms |
12108 KB |
Output is correct |
55 |
Correct |
166 ms |
22072 KB |
Output is correct |
56 |
Correct |
178 ms |
22112 KB |
Output is correct |
57 |
Correct |
77 ms |
12084 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
4 ms |
724 KB |
Output is correct |
61 |
Correct |
85 ms |
12084 KB |
Output is correct |
62 |
Correct |
0 ms |
340 KB |
Output is correct |
63 |
Correct |
0 ms |
340 KB |
Output is correct |
64 |
Correct |
0 ms |
340 KB |
Output is correct |
65 |
Correct |
42 ms |
5816 KB |
Output is correct |
66 |
Correct |
81 ms |
12356 KB |
Output is correct |
67 |
Correct |
81 ms |
12360 KB |
Output is correct |
68 |
Correct |
82 ms |
12340 KB |
Output is correct |
69 |
Correct |
78 ms |
12444 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 |
1 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 |
7 ms |
1428 KB |
Output is correct |
7 |
Correct |
174 ms |
26056 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1208 KB |
Output is correct |
13 |
Correct |
168 ms |
22076 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
85 ms |
12108 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
42 ms |
5840 KB |
Output is correct |
21 |
Correct |
171 ms |
22604 KB |
Output is correct |
22 |
Correct |
166 ms |
22136 KB |
Output is correct |
23 |
Correct |
179 ms |
24140 KB |
Output is correct |
24 |
Correct |
169 ms |
22072 KB |
Output is correct |
25 |
Correct |
78 ms |
12344 KB |
Output is correct |
26 |
Correct |
76 ms |
12100 KB |
Output is correct |
27 |
Correct |
174 ms |
25036 KB |
Output is correct |
28 |
Correct |
168 ms |
22084 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
170 ms |
22080 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
177 ms |
22080 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
4 ms |
724 KB |
Output is correct |
45 |
Correct |
86 ms |
12084 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
42 ms |
5732 KB |
Output is correct |
50 |
Correct |
172 ms |
22348 KB |
Output is correct |
51 |
Correct |
166 ms |
22072 KB |
Output is correct |
52 |
Correct |
176 ms |
22096 KB |
Output is correct |
53 |
Correct |
78 ms |
12096 KB |
Output is correct |
54 |
Correct |
78 ms |
12108 KB |
Output is correct |
55 |
Correct |
166 ms |
22072 KB |
Output is correct |
56 |
Correct |
178 ms |
22112 KB |
Output is correct |
57 |
Correct |
77 ms |
12084 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 |
51 ms |
5808 KB |
Output is correct |
62 |
Correct |
171 ms |
22584 KB |
Output is correct |
63 |
Correct |
168 ms |
22092 KB |
Output is correct |
64 |
Correct |
182 ms |
24116 KB |
Output is correct |
65 |
Correct |
0 ms |
340 KB |
Output is correct |
66 |
Correct |
42 ms |
5800 KB |
Output is correct |
67 |
Correct |
168 ms |
22076 KB |
Output is correct |
68 |
Correct |
173 ms |
22092 KB |
Output is correct |
69 |
Correct |
173 ms |
22068 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Correct |
0 ms |
340 KB |
Output is correct |
73 |
Correct |
42 ms |
5820 KB |
Output is correct |
74 |
Correct |
168 ms |
22072 KB |
Output is correct |
75 |
Correct |
169 ms |
22100 KB |
Output is correct |
76 |
Correct |
173 ms |
22076 KB |
Output is correct |
77 |
Correct |
169 ms |
22084 KB |
Output is correct |
78 |
Correct |
0 ms |
340 KB |
Output is correct |
79 |
Correct |
0 ms |
340 KB |
Output is correct |
80 |
Correct |
4 ms |
724 KB |
Output is correct |
81 |
Correct |
85 ms |
12084 KB |
Output is correct |
82 |
Correct |
0 ms |
340 KB |
Output is correct |
83 |
Correct |
0 ms |
340 KB |
Output is correct |
84 |
Correct |
0 ms |
340 KB |
Output is correct |
85 |
Correct |
42 ms |
5816 KB |
Output is correct |
86 |
Correct |
81 ms |
12356 KB |
Output is correct |
87 |
Correct |
81 ms |
12360 KB |
Output is correct |
88 |
Correct |
82 ms |
12340 KB |
Output is correct |
89 |
Correct |
78 ms |
12444 KB |
Output is correct |
90 |
Correct |
1 ms |
340 KB |
Output is correct |
91 |
Correct |
0 ms |
356 KB |
Output is correct |
92 |
Correct |
4 ms |
852 KB |
Output is correct |
93 |
Correct |
81 ms |
12340 KB |
Output is correct |
94 |
Correct |
1 ms |
340 KB |
Output is correct |
95 |
Correct |
0 ms |
340 KB |
Output is correct |
96 |
Correct |
0 ms |
340 KB |
Output is correct |
97 |
Correct |
21 ms |
3744 KB |
Output is correct |
98 |
Correct |
78 ms |
12952 KB |
Output is correct |
99 |
Correct |
80 ms |
12940 KB |
Output is correct |
100 |
Correct |
80 ms |
12860 KB |
Output is correct |
101 |
Correct |
79 ms |
12956 KB |
Output is correct |
102 |
Correct |
76 ms |
12460 KB |
Output is correct |
103 |
Correct |
76 ms |
12464 KB |
Output is correct |
104 |
Correct |
84 ms |
12556 KB |
Output is correct |
105 |
Correct |
84 ms |
12816 KB |
Output is correct |