#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef unordered_set<int> us;
int p1[1010],cc[1010];
void init(int n){
for(int i=0;i<n;i++) p1[i]=cc[i]=i;
}
int findset(int x,int sw){
if(sw==1){
if(p1[x]==x) return x;
return p1[x]=findset(p1[x],sw);
}
else{
if(cc[x]==x) return x;
return cc[x]=findset(cc[x],sw);
}
}
bool issameset(int i,int j,int sw){
return findset(i,sw)==findset(j,sw);
}
void unionset(int i,int j,int sw){
if(!issameset(i,j,sw)){
int x=findset(i,sw),y=findset(j,sw);
if(sw==1){
p1[x]=y;
}
else{
cc[x]=y;
}
}
}
int construct(std::vector<std::vector<int>> p) {
vector<vi> bu;
vector<vi> dt;
int n=p.size();
bu.resize(n);
dt.resize(n);
init(n);
for(int i=0;i<n;i++) for(int j=0;j<n;j++) bu[i].push_back(0);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j]==3) return 0;
if(i==j){
if(p[i][j]==2 or p[i][j]==0){ return 0;}
continue;
}
if(p[i][j]!=0){
if(p[i][j]==1) unionset(i,j,1);
unionset(i,j,2);
}
else{
dt[i].push_back(j);
// dt[j].push_back(i);
}
}
}
for(int i=0;i<n;i++){
// cout<<i<<": ";
for(int j=0;j<dt[i].size();j++){
// cout<<dt[i][j]<<" ";
if(issameset(dt[i][j],i,2)) return 0;
}
// cout<<endl;
}
vi an;
an.assign(n,-1);
for(int i=0;i<n;i++){
if(an[findset(i,1)]==-1){
an[findset(i,1)]=i;
}
else{
int a=an[findset(i,1)];
bu[a][i]=bu[i][a]=1;
an[findset(i,1)]=i;
}
}
vector<us> ul,pr;
ul.resize(n);
pr.resize(n);
for(int i=0;i<n;i++){
pr[findset(i,2)].insert(findset(i,1));
}
/* for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) cout<<bu[i][j]<<" ";
cout<<endl;
}*/
for(int i=0;i<n;i++){
if(pr[i].size()==2) return 0;
if(pr[i].empty()) continue;
int ant=-1,pi;
for(auto &v:pr[i]){
if(ant==-1){
pi=v;
ant=v;
}
else{
bu[ant][v]=bu[v][ant]=1;
ant=v;
}
}
if(pi!=ant)
bu[pi][ant]=bu[ant][pi]=1;
}
build(bu);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int j=0;j<dt[i].size();j++){
| ~^~~~~~~~~~~~~
supertrees.cpp:104:27: warning: 'pi' may be used uninitialized in this function [-Wmaybe-uninitialized]
104 | bu[pi][ant]=bu[ant][pi]=1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1280 KB |
Output is correct |
7 |
Correct |
270 ms |
22300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1280 KB |
Output is correct |
7 |
Correct |
270 ms |
22300 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1536 KB |
Output is correct |
13 |
Correct |
252 ms |
26488 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
134 ms |
14712 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
67 ms |
6904 KB |
Output is correct |
21 |
Correct |
265 ms |
26520 KB |
Output is correct |
22 |
Correct |
265 ms |
26360 KB |
Output is correct |
23 |
Correct |
276 ms |
24312 KB |
Output is correct |
24 |
Correct |
255 ms |
26488 KB |
Output is correct |
25 |
Correct |
121 ms |
16376 KB |
Output is correct |
26 |
Correct |
110 ms |
16248 KB |
Output is correct |
27 |
Correct |
281 ms |
25432 KB |
Output is correct |
28 |
Correct |
250 ms |
26488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
11 ms |
1536 KB |
Output is correct |
9 |
Correct |
254 ms |
26616 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1280 KB |
Output is correct |
13 |
Correct |
259 ms |
22392 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
7 ms |
896 KB |
Output is correct |
17 |
Correct |
130 ms |
14712 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
66 ms |
6904 KB |
Output is correct |
22 |
Correct |
262 ms |
26360 KB |
Output is correct |
23 |
Correct |
260 ms |
26360 KB |
Output is correct |
24 |
Correct |
277 ms |
25304 KB |
Output is correct |
25 |
Correct |
117 ms |
16476 KB |
Output is correct |
26 |
Correct |
114 ms |
16248 KB |
Output is correct |
27 |
Correct |
272 ms |
26360 KB |
Output is correct |
28 |
Correct |
273 ms |
24440 KB |
Output is correct |
29 |
Correct |
118 ms |
16476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
70 ms |
6904 KB |
Output is correct |
5 |
Correct |
264 ms |
26360 KB |
Output is correct |
6 |
Correct |
264 ms |
26404 KB |
Output is correct |
7 |
Correct |
281 ms |
24440 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
67 ms |
6904 KB |
Output is correct |
10 |
Correct |
266 ms |
26488 KB |
Output is correct |
11 |
Correct |
266 ms |
26456 KB |
Output is correct |
12 |
Correct |
271 ms |
25336 KB |
Output is correct |
13 |
Correct |
0 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
66 ms |
6996 KB |
Output is correct |
17 |
Correct |
281 ms |
26364 KB |
Output is correct |
18 |
Correct |
269 ms |
26332 KB |
Output is correct |
19 |
Correct |
263 ms |
26360 KB |
Output is correct |
20 |
Correct |
252 ms |
26360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1280 KB |
Output is correct |
7 |
Correct |
270 ms |
22300 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1536 KB |
Output is correct |
13 |
Correct |
252 ms |
26488 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
134 ms |
14712 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
67 ms |
6904 KB |
Output is correct |
21 |
Correct |
265 ms |
26520 KB |
Output is correct |
22 |
Correct |
265 ms |
26360 KB |
Output is correct |
23 |
Correct |
276 ms |
24312 KB |
Output is correct |
24 |
Correct |
255 ms |
26488 KB |
Output is correct |
25 |
Correct |
121 ms |
16376 KB |
Output is correct |
26 |
Correct |
110 ms |
16248 KB |
Output is correct |
27 |
Correct |
281 ms |
25432 KB |
Output is correct |
28 |
Correct |
250 ms |
26488 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
0 ms |
256 KB |
Output is correct |
32 |
Correct |
0 ms |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
256 KB |
Output is correct |
36 |
Correct |
11 ms |
1536 KB |
Output is correct |
37 |
Correct |
254 ms |
26616 KB |
Output is correct |
38 |
Correct |
1 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1280 KB |
Output is correct |
41 |
Correct |
259 ms |
22392 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
7 ms |
896 KB |
Output is correct |
45 |
Correct |
130 ms |
14712 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
66 ms |
6904 KB |
Output is correct |
50 |
Correct |
262 ms |
26360 KB |
Output is correct |
51 |
Correct |
260 ms |
26360 KB |
Output is correct |
52 |
Correct |
277 ms |
25304 KB |
Output is correct |
53 |
Correct |
117 ms |
16476 KB |
Output is correct |
54 |
Correct |
114 ms |
16248 KB |
Output is correct |
55 |
Correct |
272 ms |
26360 KB |
Output is correct |
56 |
Correct |
273 ms |
24440 KB |
Output is correct |
57 |
Correct |
118 ms |
16476 KB |
Output is correct |
58 |
Correct |
0 ms |
256 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
6 ms |
896 KB |
Output is correct |
61 |
Correct |
137 ms |
14328 KB |
Output is correct |
62 |
Correct |
1 ms |
256 KB |
Output is correct |
63 |
Correct |
1 ms |
384 KB |
Output is correct |
64 |
Correct |
0 ms |
384 KB |
Output is correct |
65 |
Correct |
69 ms |
7032 KB |
Output is correct |
66 |
Correct |
114 ms |
16248 KB |
Output is correct |
67 |
Correct |
112 ms |
16248 KB |
Output is correct |
68 |
Correct |
110 ms |
16248 KB |
Output is correct |
69 |
Correct |
115 ms |
16504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
12 ms |
1280 KB |
Output is correct |
7 |
Correct |
270 ms |
22300 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
11 ms |
1536 KB |
Output is correct |
13 |
Correct |
252 ms |
26488 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
896 KB |
Output is correct |
17 |
Correct |
134 ms |
14712 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
67 ms |
6904 KB |
Output is correct |
21 |
Correct |
265 ms |
26520 KB |
Output is correct |
22 |
Correct |
265 ms |
26360 KB |
Output is correct |
23 |
Correct |
276 ms |
24312 KB |
Output is correct |
24 |
Correct |
255 ms |
26488 KB |
Output is correct |
25 |
Correct |
121 ms |
16376 KB |
Output is correct |
26 |
Correct |
110 ms |
16248 KB |
Output is correct |
27 |
Correct |
281 ms |
25432 KB |
Output is correct |
28 |
Correct |
250 ms |
26488 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
256 KB |
Output is correct |
31 |
Correct |
0 ms |
256 KB |
Output is correct |
32 |
Correct |
0 ms |
256 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
256 KB |
Output is correct |
36 |
Correct |
11 ms |
1536 KB |
Output is correct |
37 |
Correct |
254 ms |
26616 KB |
Output is correct |
38 |
Correct |
1 ms |
256 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1280 KB |
Output is correct |
41 |
Correct |
259 ms |
22392 KB |
Output is correct |
42 |
Correct |
1 ms |
256 KB |
Output is correct |
43 |
Correct |
0 ms |
256 KB |
Output is correct |
44 |
Correct |
7 ms |
896 KB |
Output is correct |
45 |
Correct |
130 ms |
14712 KB |
Output is correct |
46 |
Correct |
1 ms |
256 KB |
Output is correct |
47 |
Correct |
0 ms |
256 KB |
Output is correct |
48 |
Correct |
1 ms |
256 KB |
Output is correct |
49 |
Correct |
66 ms |
6904 KB |
Output is correct |
50 |
Correct |
262 ms |
26360 KB |
Output is correct |
51 |
Correct |
260 ms |
26360 KB |
Output is correct |
52 |
Correct |
277 ms |
25304 KB |
Output is correct |
53 |
Correct |
117 ms |
16476 KB |
Output is correct |
54 |
Correct |
114 ms |
16248 KB |
Output is correct |
55 |
Correct |
272 ms |
26360 KB |
Output is correct |
56 |
Correct |
273 ms |
24440 KB |
Output is correct |
57 |
Correct |
118 ms |
16476 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
0 ms |
256 KB |
Output is correct |
60 |
Correct |
0 ms |
256 KB |
Output is correct |
61 |
Correct |
70 ms |
6904 KB |
Output is correct |
62 |
Correct |
264 ms |
26360 KB |
Output is correct |
63 |
Correct |
264 ms |
26404 KB |
Output is correct |
64 |
Correct |
281 ms |
24440 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
67 ms |
6904 KB |
Output is correct |
67 |
Correct |
266 ms |
26488 KB |
Output is correct |
68 |
Correct |
266 ms |
26456 KB |
Output is correct |
69 |
Correct |
271 ms |
25336 KB |
Output is correct |
70 |
Correct |
0 ms |
256 KB |
Output is correct |
71 |
Correct |
1 ms |
256 KB |
Output is correct |
72 |
Correct |
0 ms |
256 KB |
Output is correct |
73 |
Correct |
66 ms |
6996 KB |
Output is correct |
74 |
Correct |
281 ms |
26364 KB |
Output is correct |
75 |
Correct |
269 ms |
26332 KB |
Output is correct |
76 |
Correct |
263 ms |
26360 KB |
Output is correct |
77 |
Correct |
252 ms |
26360 KB |
Output is correct |
78 |
Correct |
0 ms |
256 KB |
Output is correct |
79 |
Correct |
0 ms |
256 KB |
Output is correct |
80 |
Correct |
6 ms |
896 KB |
Output is correct |
81 |
Correct |
137 ms |
14328 KB |
Output is correct |
82 |
Correct |
1 ms |
256 KB |
Output is correct |
83 |
Correct |
1 ms |
384 KB |
Output is correct |
84 |
Correct |
0 ms |
384 KB |
Output is correct |
85 |
Correct |
69 ms |
7032 KB |
Output is correct |
86 |
Correct |
114 ms |
16248 KB |
Output is correct |
87 |
Correct |
112 ms |
16248 KB |
Output is correct |
88 |
Correct |
110 ms |
16248 KB |
Output is correct |
89 |
Correct |
115 ms |
16504 KB |
Output is correct |
90 |
Correct |
0 ms |
256 KB |
Output is correct |
91 |
Correct |
0 ms |
256 KB |
Output is correct |
92 |
Correct |
5 ms |
896 KB |
Output is correct |
93 |
Correct |
106 ms |
12280 KB |
Output is correct |
94 |
Correct |
1 ms |
256 KB |
Output is correct |
95 |
Correct |
1 ms |
256 KB |
Output is correct |
96 |
Correct |
1 ms |
384 KB |
Output is correct |
97 |
Correct |
27 ms |
3448 KB |
Output is correct |
98 |
Correct |
108 ms |
12536 KB |
Output is correct |
99 |
Correct |
111 ms |
12920 KB |
Output is correct |
100 |
Correct |
101 ms |
12536 KB |
Output is correct |
101 |
Correct |
104 ms |
13664 KB |
Output is correct |
102 |
Correct |
109 ms |
12280 KB |
Output is correct |
103 |
Correct |
112 ms |
12408 KB |
Output is correct |
104 |
Correct |
112 ms |
12280 KB |
Output is correct |
105 |
Correct |
109 ms |
12284 KB |
Output is correct |