#include "supertrees.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
struct DSU{
vector<int> p,sz;
void build(int n){
p.resize(n);
sz.resize(n);
for(int i=0;i<n;i++){
p[i]=i;
sz[i]=1;
}
}
int f(int x){
if(p[x]==x) return x;
return p[x]=f(p[x]);
}
void add_edge(int a, int b){
a=f(a);b=f(b);
if(a==b) return;
if(sz[a]>sz[b]) swap(a,b);
p[a]=b;
sz[b]+=sz[a];
}
};
int construct(vector<vector<int>> p) {
int n = p.size();
DSU trees,comp;
trees.build(n);comp.build(n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j]==3) return 0;
if(p[i][j]==1)
trees.add_edge(i,j);
if(p[i][j]>0)
comp.add_edge(i,j);
}
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j]==0 && comp.f(i)==comp.f(j)) return 0;
if(p[i][j]!=0 && comp.f(i)!=comp.f(j)) return 0;
if(p[i][j]==1 && trees.f(i)!=trees.f(j)) return 0;
if(p[i][j]!=1 && trees.f(i)==trees.f(j)) return 0;
if(p[i][j]==2 && comp.f(i)!=comp.f(j) && trees.f(i)==trees.f(j)) return 0;
if(p[i][j]!=2 && comp.f(i)==comp.f(j) && trees.f(i)!=trees.f(j)) return 0;
}
}
vector<int> used(n);
vector<vector<int>> b(n,vector<int>(n,0));
vector<vector<int>> v(n);
for(int i=0;i<n;i++){
if(!used[i]){
used[i]=1;
v[comp.f(i)].push_back(i);
for(int j=0;j<n;j++){
if(j!=i && trees.f(i)==trees.f(j)){
b[i][j]=b[j][i]=1;
used[j]=1;
}
}
}
}
for(auto it: v){
if(it.size()==2) return 0;
if(it.size()>2){
for(int i=0;i<(int)it.size();i++){
b[it[i]][(it[(i+1)%(int)it.size()])]=b[(it[(i+1)%(int)it.size()])][it[i]]=1;
}
}
}
build(b);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1172 KB |
Output is correct |
7 |
Correct |
201 ms |
22036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1172 KB |
Output is correct |
7 |
Correct |
201 ms |
22036 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1108 KB |
Output is correct |
13 |
Correct |
215 ms |
22040 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
82 ms |
10100 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
52 ms |
6260 KB |
Output is correct |
21 |
Correct |
187 ms |
24080 KB |
Output is correct |
22 |
Correct |
186 ms |
24060 KB |
Output is correct |
23 |
Correct |
198 ms |
23936 KB |
Output is correct |
24 |
Correct |
178 ms |
24100 KB |
Output is correct |
25 |
Correct |
76 ms |
10100 KB |
Output is correct |
26 |
Correct |
74 ms |
10100 KB |
Output is correct |
27 |
Correct |
199 ms |
24032 KB |
Output is correct |
28 |
Correct |
194 ms |
23960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1108 KB |
Output is correct |
9 |
Correct |
182 ms |
22160 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
11 ms |
1108 KB |
Output is correct |
13 |
Correct |
202 ms |
22020 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
708 KB |
Output is correct |
17 |
Correct |
82 ms |
10060 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
53 ms |
6188 KB |
Output is correct |
22 |
Correct |
187 ms |
23936 KB |
Output is correct |
23 |
Correct |
213 ms |
24092 KB |
Output is correct |
24 |
Correct |
200 ms |
23988 KB |
Output is correct |
25 |
Correct |
101 ms |
14124 KB |
Output is correct |
26 |
Correct |
70 ms |
10116 KB |
Output is correct |
27 |
Correct |
193 ms |
24140 KB |
Output is correct |
28 |
Correct |
209 ms |
24104 KB |
Output is correct |
29 |
Correct |
82 ms |
14144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
54 ms |
5764 KB |
Output is correct |
5 |
Correct |
195 ms |
22044 KB |
Output is correct |
6 |
Correct |
191 ms |
22020 KB |
Output is correct |
7 |
Correct |
195 ms |
22016 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
46 ms |
5708 KB |
Output is correct |
10 |
Correct |
183 ms |
22028 KB |
Output is correct |
11 |
Correct |
192 ms |
22008 KB |
Output is correct |
12 |
Correct |
199 ms |
22024 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
51 ms |
5672 KB |
Output is correct |
17 |
Correct |
189 ms |
22168 KB |
Output is correct |
18 |
Correct |
189 ms |
22024 KB |
Output is correct |
19 |
Correct |
198 ms |
22100 KB |
Output is correct |
20 |
Correct |
177 ms |
22020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1172 KB |
Output is correct |
7 |
Correct |
201 ms |
22036 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1108 KB |
Output is correct |
13 |
Correct |
215 ms |
22040 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
82 ms |
10100 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
52 ms |
6260 KB |
Output is correct |
21 |
Correct |
187 ms |
24080 KB |
Output is correct |
22 |
Correct |
186 ms |
24060 KB |
Output is correct |
23 |
Correct |
198 ms |
23936 KB |
Output is correct |
24 |
Correct |
178 ms |
24100 KB |
Output is correct |
25 |
Correct |
76 ms |
10100 KB |
Output is correct |
26 |
Correct |
74 ms |
10100 KB |
Output is correct |
27 |
Correct |
199 ms |
24032 KB |
Output is correct |
28 |
Correct |
194 ms |
23960 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1108 KB |
Output is correct |
37 |
Correct |
182 ms |
22160 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
11 ms |
1108 KB |
Output is correct |
41 |
Correct |
202 ms |
22020 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
708 KB |
Output is correct |
45 |
Correct |
82 ms |
10060 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
53 ms |
6188 KB |
Output is correct |
50 |
Correct |
187 ms |
23936 KB |
Output is correct |
51 |
Correct |
213 ms |
24092 KB |
Output is correct |
52 |
Correct |
200 ms |
23988 KB |
Output is correct |
53 |
Correct |
101 ms |
14124 KB |
Output is correct |
54 |
Correct |
70 ms |
10116 KB |
Output is correct |
55 |
Correct |
193 ms |
24140 KB |
Output is correct |
56 |
Correct |
209 ms |
24104 KB |
Output is correct |
57 |
Correct |
82 ms |
14144 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
596 KB |
Output is correct |
61 |
Correct |
88 ms |
10060 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
300 KB |
Output is correct |
64 |
Correct |
0 ms |
300 KB |
Output is correct |
65 |
Correct |
52 ms |
6260 KB |
Output is correct |
66 |
Correct |
74 ms |
10100 KB |
Output is correct |
67 |
Correct |
73 ms |
10104 KB |
Output is correct |
68 |
Correct |
74 ms |
10096 KB |
Output is correct |
69 |
Correct |
87 ms |
14120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1172 KB |
Output is correct |
7 |
Correct |
201 ms |
22036 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1108 KB |
Output is correct |
13 |
Correct |
215 ms |
22040 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
596 KB |
Output is correct |
17 |
Correct |
82 ms |
10100 KB |
Output is correct |
18 |
Correct |
1 ms |
300 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
52 ms |
6260 KB |
Output is correct |
21 |
Correct |
187 ms |
24080 KB |
Output is correct |
22 |
Correct |
186 ms |
24060 KB |
Output is correct |
23 |
Correct |
198 ms |
23936 KB |
Output is correct |
24 |
Correct |
178 ms |
24100 KB |
Output is correct |
25 |
Correct |
76 ms |
10100 KB |
Output is correct |
26 |
Correct |
74 ms |
10100 KB |
Output is correct |
27 |
Correct |
199 ms |
24032 KB |
Output is correct |
28 |
Correct |
194 ms |
23960 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1108 KB |
Output is correct |
37 |
Correct |
182 ms |
22160 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
11 ms |
1108 KB |
Output is correct |
41 |
Correct |
202 ms |
22020 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
708 KB |
Output is correct |
45 |
Correct |
82 ms |
10060 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
53 ms |
6188 KB |
Output is correct |
50 |
Correct |
187 ms |
23936 KB |
Output is correct |
51 |
Correct |
213 ms |
24092 KB |
Output is correct |
52 |
Correct |
200 ms |
23988 KB |
Output is correct |
53 |
Correct |
101 ms |
14124 KB |
Output is correct |
54 |
Correct |
70 ms |
10116 KB |
Output is correct |
55 |
Correct |
193 ms |
24140 KB |
Output is correct |
56 |
Correct |
209 ms |
24104 KB |
Output is correct |
57 |
Correct |
82 ms |
14144 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
54 ms |
5764 KB |
Output is correct |
62 |
Correct |
195 ms |
22044 KB |
Output is correct |
63 |
Correct |
191 ms |
22020 KB |
Output is correct |
64 |
Correct |
195 ms |
22016 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
46 ms |
5708 KB |
Output is correct |
67 |
Correct |
183 ms |
22028 KB |
Output is correct |
68 |
Correct |
192 ms |
22008 KB |
Output is correct |
69 |
Correct |
199 ms |
22024 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
51 ms |
5672 KB |
Output is correct |
74 |
Correct |
189 ms |
22168 KB |
Output is correct |
75 |
Correct |
189 ms |
22024 KB |
Output is correct |
76 |
Correct |
198 ms |
22100 KB |
Output is correct |
77 |
Correct |
177 ms |
22020 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
596 KB |
Output is correct |
81 |
Correct |
88 ms |
10060 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
300 KB |
Output is correct |
84 |
Correct |
0 ms |
300 KB |
Output is correct |
85 |
Correct |
52 ms |
6260 KB |
Output is correct |
86 |
Correct |
74 ms |
10100 KB |
Output is correct |
87 |
Correct |
73 ms |
10104 KB |
Output is correct |
88 |
Correct |
74 ms |
10096 KB |
Output is correct |
89 |
Correct |
87 ms |
14120 KB |
Output is correct |
90 |
Correct |
1 ms |
300 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
4 ms |
692 KB |
Output is correct |
93 |
Correct |
85 ms |
10108 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
300 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
22 ms |
2684 KB |
Output is correct |
98 |
Correct |
69 ms |
10060 KB |
Output is correct |
99 |
Correct |
70 ms |
10112 KB |
Output is correct |
100 |
Correct |
70 ms |
10100 KB |
Output is correct |
101 |
Correct |
74 ms |
10096 KB |
Output is correct |
102 |
Correct |
79 ms |
10104 KB |
Output is correct |
103 |
Correct |
71 ms |
10100 KB |
Output is correct |
104 |
Correct |
70 ms |
10100 KB |
Output is correct |
105 |
Correct |
76 ms |
10152 KB |
Output is correct |