#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int construct(vector<vector<int>>p){
int n=p.size();
vector<bool>a(4,0);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j) continue;
a[p[i][j]]=true;
}
}
vector<vector<int>>b(n,vector<int>(n,0));
if(!a[2]&&!a[3]){
vector<bool>used(n,0);
vector<int>ver;
for(int i=0;i<n;i++){
if(!used[i]){
queue<int>q;
q.push(i);
used[i]=true;
while(!q.empty()){
int x=q.front();
ver.pb(x);
q.pop();
for(int j=0;j<n;j++){
if(p[x][j]==1&&!used[j]){
used[j]=true;
q.push(j);
}
}
}
for(auto x:ver){
for(auto y:ver){
if(x!=y&&p[x][y]!=1){
return 0;
}
}
}
for(int j=1;j<ver.size();j++){
b[ver[j]][ver[j-1]]=1;
b[ver[j-1]][ver[j]]=1;
}
ver.clear();
}
}
build(b);
return 1;
}
if(!a[1]&&!a[3]){
vector<bool>used(n,0);
vector<int>ver;
for(int i=0;i<n;i++){
if(!used[i]){
queue<int>q;
q.push(i);
used[i]=true;
while(!q.empty()){
int x=q.front();
ver.pb(x);
q.pop();
for(int j=0;j<n;j++){
if(p[x][j]==2&&!used[j]){
used[j]=true;
q.push(j);
}
}
}
if(ver.size()==2){
return 0;
}
for(auto x:ver){
for(auto y:ver){
if(x!=y&&p[x][y]!=2){
return 0;
}
}
}
for(int j=1;j<ver.size();j++){
b[ver[j]][ver[j-1]]=1;
b[ver[j-1]][ver[j]]=1;
}
if(ver.size()>1){
b[ver[0]][ver.back()]=1;
b[ver.back()][ver[0]]=1;
}
ver.clear();
}
}
build(b);
return 1;
}
return 0;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:49:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int j=1;j<ver.size();j++){
| ~^~~~~~~~~~~
supertrees.cpp:88:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int j=1;j<ver.size();j++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
155 ms |
22100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
155 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1324 KB |
Output is correct |
13 |
Correct |
155 ms |
22148 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
74 ms |
12056 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
5720 KB |
Output is correct |
21 |
Correct |
154 ms |
22024 KB |
Output is correct |
22 |
Correct |
152 ms |
22028 KB |
Output is correct |
23 |
Correct |
157 ms |
22104 KB |
Output is correct |
24 |
Correct |
156 ms |
21980 KB |
Output is correct |
25 |
Correct |
63 ms |
12116 KB |
Output is correct |
26 |
Correct |
60 ms |
12056 KB |
Output is correct |
27 |
Correct |
158 ms |
22100 KB |
Output is correct |
28 |
Correct |
154 ms |
22104 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
7 ms |
1372 KB |
Output is correct |
9 |
Correct |
152 ms |
24088 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1372 KB |
Output is correct |
13 |
Correct |
156 ms |
23892 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
936 KB |
Output is correct |
17 |
Correct |
73 ms |
14164 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
39 ms |
6236 KB |
Output is correct |
22 |
Correct |
159 ms |
23928 KB |
Output is correct |
23 |
Correct |
157 ms |
23892 KB |
Output is correct |
24 |
Correct |
165 ms |
24660 KB |
Output is correct |
25 |
Correct |
61 ms |
14084 KB |
Output is correct |
26 |
Correct |
61 ms |
14088 KB |
Output is correct |
27 |
Correct |
152 ms |
23936 KB |
Output is correct |
28 |
Correct |
156 ms |
23892 KB |
Output is correct |
29 |
Correct |
61 ms |
14080 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 |
39 ms |
5724 KB |
Output is correct |
5 |
Correct |
153 ms |
22100 KB |
Output is correct |
6 |
Correct |
152 ms |
22096 KB |
Output is correct |
7 |
Correct |
157 ms |
22124 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
38 ms |
5728 KB |
Output is correct |
10 |
Correct |
153 ms |
22100 KB |
Output is correct |
11 |
Correct |
156 ms |
22084 KB |
Output is correct |
12 |
Correct |
156 ms |
22100 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
155 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1324 KB |
Output is correct |
13 |
Correct |
155 ms |
22148 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
74 ms |
12056 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
5720 KB |
Output is correct |
21 |
Correct |
154 ms |
22024 KB |
Output is correct |
22 |
Correct |
152 ms |
22028 KB |
Output is correct |
23 |
Correct |
157 ms |
22104 KB |
Output is correct |
24 |
Correct |
156 ms |
21980 KB |
Output is correct |
25 |
Correct |
63 ms |
12116 KB |
Output is correct |
26 |
Correct |
60 ms |
12056 KB |
Output is correct |
27 |
Correct |
158 ms |
22100 KB |
Output is correct |
28 |
Correct |
154 ms |
22104 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
7 ms |
1372 KB |
Output is correct |
37 |
Correct |
152 ms |
24088 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1372 KB |
Output is correct |
41 |
Correct |
156 ms |
23892 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
936 KB |
Output is correct |
45 |
Correct |
73 ms |
14164 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
39 ms |
6236 KB |
Output is correct |
50 |
Correct |
159 ms |
23928 KB |
Output is correct |
51 |
Correct |
157 ms |
23892 KB |
Output is correct |
52 |
Correct |
165 ms |
24660 KB |
Output is correct |
53 |
Correct |
61 ms |
14084 KB |
Output is correct |
54 |
Correct |
61 ms |
14088 KB |
Output is correct |
55 |
Correct |
152 ms |
23936 KB |
Output is correct |
56 |
Correct |
156 ms |
23892 KB |
Output is correct |
57 |
Correct |
61 ms |
14080 KB |
Output is correct |
58 |
Correct |
1 ms |
432 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
860 KB |
Output is correct |
61 |
Correct |
66 ms |
14212 KB |
Output is correct |
62 |
Correct |
1 ms |
348 KB |
Output is correct |
63 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
64 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
7 ms |
1116 KB |
Output is correct |
7 |
Correct |
155 ms |
22100 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1324 KB |
Output is correct |
13 |
Correct |
155 ms |
22148 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
74 ms |
12056 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
38 ms |
5720 KB |
Output is correct |
21 |
Correct |
154 ms |
22024 KB |
Output is correct |
22 |
Correct |
152 ms |
22028 KB |
Output is correct |
23 |
Correct |
157 ms |
22104 KB |
Output is correct |
24 |
Correct |
156 ms |
21980 KB |
Output is correct |
25 |
Correct |
63 ms |
12116 KB |
Output is correct |
26 |
Correct |
60 ms |
12056 KB |
Output is correct |
27 |
Correct |
158 ms |
22100 KB |
Output is correct |
28 |
Correct |
154 ms |
22104 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
7 ms |
1372 KB |
Output is correct |
37 |
Correct |
152 ms |
24088 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1372 KB |
Output is correct |
41 |
Correct |
156 ms |
23892 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
936 KB |
Output is correct |
45 |
Correct |
73 ms |
14164 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
39 ms |
6236 KB |
Output is correct |
50 |
Correct |
159 ms |
23928 KB |
Output is correct |
51 |
Correct |
157 ms |
23892 KB |
Output is correct |
52 |
Correct |
165 ms |
24660 KB |
Output is correct |
53 |
Correct |
61 ms |
14084 KB |
Output is correct |
54 |
Correct |
61 ms |
14088 KB |
Output is correct |
55 |
Correct |
152 ms |
23936 KB |
Output is correct |
56 |
Correct |
156 ms |
23892 KB |
Output is correct |
57 |
Correct |
61 ms |
14080 KB |
Output is correct |
58 |
Correct |
0 ms |
344 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
39 ms |
5724 KB |
Output is correct |
62 |
Correct |
153 ms |
22100 KB |
Output is correct |
63 |
Correct |
152 ms |
22096 KB |
Output is correct |
64 |
Correct |
157 ms |
22124 KB |
Output is correct |
65 |
Correct |
1 ms |
344 KB |
Output is correct |
66 |
Correct |
38 ms |
5728 KB |
Output is correct |
67 |
Correct |
153 ms |
22100 KB |
Output is correct |
68 |
Correct |
156 ms |
22084 KB |
Output is correct |
69 |
Correct |
156 ms |
22100 KB |
Output is correct |
70 |
Correct |
0 ms |
348 KB |
Output is correct |
71 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
72 |
Halted |
0 ms |
0 KB |
- |