#include "bits/stdc++.h"
#include "supertrees.h"
using namespace std;
int pr[100001];
int find(int x){
if(x==pr[x])return x;
return pr[x] = find(pr[x]);
}
void mergegroup(int a,int b){
a = find(a);
b = find(b);
if(a==b)return ;
pr[a] = b;
}
int pr2[100001];
int find2(int x){
if(x==pr2[x])return x;
return pr2[x] = find2(pr2[x]);
}
void mergegroup2(int a,int b){
a = find2(a);
b = find2(b);
if(a==b)return ;
pr2[a] = b;
}
int construct(vector<vector<int>> p){
int n = p.size();
vector<vector<int>> B;
vector<int> x(n,0);
for(int i = 0;i<n;i++){
B.push_back(x);
}
//phase 1
for(int i = 0;i<n;i++){
pr[i] = i;
}
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if(p[i][j]==3){
return 0;
}
if(i==j)continue;
if(p[i][j]){
mergegroup(i,j);
}
}
}
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if(i==j)continue;
if(find(i)==find(j)){
if(p[i][j]==0){
return 0;
}
}else{
if(p[i][j]){
return 0;
}
}
}
}
//phase 2
for(int i = 0;i<n;i++){
pr2[i] = i;
}
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if(i==j)continue;
if(p[i][j]==1){
mergegroup2(i,j);
}
}
}
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
if(i==j)continue;
if(find2(i)==find2(j)){
if(p[i][j]!=1){
return 0;
}
}else{
if(p[i][j]==1){
return 0;
}
}
}
}
for(int i = 0;i<n;i++){
if(i==find(i)){
vector<int> lol;
for(int j = 0;j<n;j++){
if(find(i)==find(j)){
lol.push_back(j);
}
}
vector<int> ror[n];
for(int j:lol){
ror[find2(j)].push_back(j);
}
vector<int> nah;
for(int j = 0;j<n;j++){
if(ror[j].size()){
nah.push_back(j);
}
for(int e = 1;e<ror[j].size();e++){
B[ror[j][e-1]][ror[j][e]]=1;
B[ror[j][e]][ror[j][e-1]]=1;
}
}
if(nah.size()==2){
return 0;
}
for(int j = 0;j<nah.size();j++){
int a = nah[j] , b = nah[(j+1)%nah.size()];
B[a][b] = 1;
B[b][a] = 1;
}
}
}
for(int i = 0;i<n;i++)B[i][i] = 0;
build(B);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:106:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int e = 1;e<ror[j].size();e++){
| ~^~~~~~~~~~~~~~
supertrees.cpp:114:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
114 | for(int j = 0;j<nah.size();j++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1116 KB |
Output is correct |
7 |
Correct |
114 ms |
22044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1116 KB |
Output is correct |
7 |
Correct |
114 ms |
22044 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
1116 KB |
Output is correct |
13 |
Correct |
123 ms |
22100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
53 ms |
12116 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
30 ms |
5832 KB |
Output is correct |
21 |
Correct |
112 ms |
22096 KB |
Output is correct |
22 |
Correct |
120 ms |
22040 KB |
Output is correct |
23 |
Correct |
122 ms |
22224 KB |
Output is correct |
24 |
Correct |
113 ms |
22096 KB |
Output is correct |
25 |
Correct |
48 ms |
12112 KB |
Output is correct |
26 |
Correct |
45 ms |
12116 KB |
Output is correct |
27 |
Correct |
112 ms |
22096 KB |
Output is correct |
28 |
Correct |
117 ms |
22048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
5 ms |
1112 KB |
Output is correct |
9 |
Correct |
122 ms |
22052 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
4 ms |
1288 KB |
Output is correct |
13 |
Correct |
138 ms |
22048 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
440 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
56 ms |
12048 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
27 ms |
5908 KB |
Output is correct |
22 |
Correct |
129 ms |
22100 KB |
Output is correct |
23 |
Correct |
101 ms |
22100 KB |
Output is correct |
24 |
Correct |
106 ms |
22052 KB |
Output is correct |
25 |
Correct |
62 ms |
12112 KB |
Output is correct |
26 |
Correct |
47 ms |
12116 KB |
Output is correct |
27 |
Correct |
111 ms |
22024 KB |
Output is correct |
28 |
Correct |
125 ms |
22052 KB |
Output is correct |
29 |
Correct |
64 ms |
12064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
31 ms |
5904 KB |
Output is correct |
5 |
Correct |
112 ms |
22212 KB |
Output is correct |
6 |
Correct |
113 ms |
22100 KB |
Output is correct |
7 |
Correct |
125 ms |
22100 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
45 ms |
5924 KB |
Output is correct |
10 |
Correct |
121 ms |
22020 KB |
Output is correct |
11 |
Correct |
113 ms |
22100 KB |
Output is correct |
12 |
Correct |
129 ms |
22096 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
30 ms |
5880 KB |
Output is correct |
17 |
Correct |
121 ms |
22172 KB |
Output is correct |
18 |
Correct |
120 ms |
22096 KB |
Output is correct |
19 |
Correct |
119 ms |
22096 KB |
Output is correct |
20 |
Correct |
124 ms |
22096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1116 KB |
Output is correct |
7 |
Correct |
114 ms |
22044 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
1116 KB |
Output is correct |
13 |
Correct |
123 ms |
22100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
53 ms |
12116 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
30 ms |
5832 KB |
Output is correct |
21 |
Correct |
112 ms |
22096 KB |
Output is correct |
22 |
Correct |
120 ms |
22040 KB |
Output is correct |
23 |
Correct |
122 ms |
22224 KB |
Output is correct |
24 |
Correct |
113 ms |
22096 KB |
Output is correct |
25 |
Correct |
48 ms |
12112 KB |
Output is correct |
26 |
Correct |
45 ms |
12116 KB |
Output is correct |
27 |
Correct |
112 ms |
22096 KB |
Output is correct |
28 |
Correct |
117 ms |
22048 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1112 KB |
Output is correct |
37 |
Correct |
122 ms |
22052 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
4 ms |
1288 KB |
Output is correct |
41 |
Correct |
138 ms |
22048 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
440 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
56 ms |
12048 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
27 ms |
5908 KB |
Output is correct |
50 |
Correct |
129 ms |
22100 KB |
Output is correct |
51 |
Correct |
101 ms |
22100 KB |
Output is correct |
52 |
Correct |
106 ms |
22052 KB |
Output is correct |
53 |
Correct |
62 ms |
12112 KB |
Output is correct |
54 |
Correct |
47 ms |
12116 KB |
Output is correct |
55 |
Correct |
111 ms |
22024 KB |
Output is correct |
56 |
Correct |
125 ms |
22052 KB |
Output is correct |
57 |
Correct |
64 ms |
12064 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
860 KB |
Output is correct |
61 |
Correct |
79 ms |
12052 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
0 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
31 ms |
5792 KB |
Output is correct |
66 |
Correct |
51 ms |
12068 KB |
Output is correct |
67 |
Correct |
50 ms |
12112 KB |
Output is correct |
68 |
Correct |
49 ms |
12068 KB |
Output is correct |
69 |
Correct |
60 ms |
12076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1116 KB |
Output is correct |
7 |
Correct |
114 ms |
22044 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
1116 KB |
Output is correct |
13 |
Correct |
123 ms |
22100 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
860 KB |
Output is correct |
17 |
Correct |
53 ms |
12116 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
30 ms |
5832 KB |
Output is correct |
21 |
Correct |
112 ms |
22096 KB |
Output is correct |
22 |
Correct |
120 ms |
22040 KB |
Output is correct |
23 |
Correct |
122 ms |
22224 KB |
Output is correct |
24 |
Correct |
113 ms |
22096 KB |
Output is correct |
25 |
Correct |
48 ms |
12112 KB |
Output is correct |
26 |
Correct |
45 ms |
12116 KB |
Output is correct |
27 |
Correct |
112 ms |
22096 KB |
Output is correct |
28 |
Correct |
117 ms |
22048 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1112 KB |
Output is correct |
37 |
Correct |
122 ms |
22052 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
4 ms |
1288 KB |
Output is correct |
41 |
Correct |
138 ms |
22048 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
440 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
56 ms |
12048 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
27 ms |
5908 KB |
Output is correct |
50 |
Correct |
129 ms |
22100 KB |
Output is correct |
51 |
Correct |
101 ms |
22100 KB |
Output is correct |
52 |
Correct |
106 ms |
22052 KB |
Output is correct |
53 |
Correct |
62 ms |
12112 KB |
Output is correct |
54 |
Correct |
47 ms |
12116 KB |
Output is correct |
55 |
Correct |
111 ms |
22024 KB |
Output is correct |
56 |
Correct |
125 ms |
22052 KB |
Output is correct |
57 |
Correct |
64 ms |
12064 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
31 ms |
5904 KB |
Output is correct |
62 |
Correct |
112 ms |
22212 KB |
Output is correct |
63 |
Correct |
113 ms |
22100 KB |
Output is correct |
64 |
Correct |
125 ms |
22100 KB |
Output is correct |
65 |
Correct |
1 ms |
344 KB |
Output is correct |
66 |
Correct |
45 ms |
5924 KB |
Output is correct |
67 |
Correct |
121 ms |
22020 KB |
Output is correct |
68 |
Correct |
113 ms |
22100 KB |
Output is correct |
69 |
Correct |
129 ms |
22096 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |
71 |
Correct |
0 ms |
344 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
30 ms |
5880 KB |
Output is correct |
74 |
Correct |
121 ms |
22172 KB |
Output is correct |
75 |
Correct |
120 ms |
22096 KB |
Output is correct |
76 |
Correct |
119 ms |
22096 KB |
Output is correct |
77 |
Correct |
124 ms |
22096 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
3 ms |
860 KB |
Output is correct |
81 |
Correct |
79 ms |
12052 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
31 ms |
5792 KB |
Output is correct |
86 |
Correct |
51 ms |
12068 KB |
Output is correct |
87 |
Correct |
50 ms |
12112 KB |
Output is correct |
88 |
Correct |
49 ms |
12068 KB |
Output is correct |
89 |
Correct |
60 ms |
12076 KB |
Output is correct |
90 |
Correct |
0 ms |
348 KB |
Output is correct |
91 |
Correct |
0 ms |
348 KB |
Output is correct |
92 |
Correct |
2 ms |
860 KB |
Output is correct |
93 |
Correct |
51 ms |
12052 KB |
Output is correct |
94 |
Correct |
1 ms |
344 KB |
Output is correct |
95 |
Correct |
0 ms |
348 KB |
Output is correct |
96 |
Correct |
0 ms |
348 KB |
Output is correct |
97 |
Correct |
12 ms |
3932 KB |
Output is correct |
98 |
Correct |
55 ms |
14164 KB |
Output is correct |
99 |
Correct |
50 ms |
14164 KB |
Output is correct |
100 |
Correct |
69 ms |
14124 KB |
Output is correct |
101 |
Correct |
52 ms |
14088 KB |
Output is correct |
102 |
Correct |
49 ms |
14232 KB |
Output is correct |
103 |
Correct |
53 ms |
14084 KB |
Output is correct |
104 |
Correct |
48 ms |
14224 KB |
Output is correct |
105 |
Correct |
54 ms |
14088 KB |
Output is correct |