#include "supertrees.h"
#include <vector>
#include <set>
#include <iostream>
using namespace std;
vector<int> parent(1005,0);
vector<int> parentg(1005,0);
int get_parent(int a){
if(a == parent[a])return a;
return get_parent(parent[a]);
}
int get_parentg(int a){
if(a == parentg[a])return a;
return get_parentg(parentg[a]);
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer(n, vector<int>(n,0));
for(int i=0;i<n;i++)parent[i]=i;
for(int i=0;i<n;i++)parentg[i]=i;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(p[i][j] == 3)return 0;
if(p[i][j] == 1){
if(get_parent(i) == get_parent(j))continue;
answer[i][j] = 1;
answer[j][i] = 1;
parent[j] = get_parent(i);
parentg[j] = parent[j];
}
}
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(p[i][j] == 2){
int a = get_parent(i), b = get_parent(j);
if(a==b)
return 0;
if(get_parentg(a) == get_parentg(b))continue;
if(a>b)swap(a,b);
parentg[b] = get_parentg(a);
}
}
}
vector<set<int>> heads(1005);
for(int i=0;i<n;i++){
heads[get_parentg(i)].insert(get_parent(i));
}
for(int i=0;i<n;i++){
vector<int> temp;
for(int a:heads[i])temp.push_back(a);
int m = temp.size();
if(m < 2)continue;
for(int j = 0;j<=temp.size();j++){
answer[temp[j%m]][temp[(j+1)%m]] = 1;
answer[temp[(j+1)%m]][temp[j%m]] = 1;
}
}
cerr << endl;
for(int i=0;i<n;i++)cerr << get_parent(i) << " ";
cerr << endl;
for(int i=0;i<n;i++)cerr << get_parentg(i) << " ";
cerr << endl;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
int a = get_parent(i), b = get_parent(j);
int c = get_parentg(a), d = get_parentg(b);
if(p[i][j] == 0){
if(a == b)return 0;
if(c == d)return 0;
}
if(p[i][j] == 1){
if(a != b)return 0;
}
if(p[i][j] == 2){
if(heads[c].size() < 2)return 0;
if(a == b)return 0;
if(c != d)return 0;
}
}
}
build(answer);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int j = 0;j<=temp.size();j++){
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
352 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
119 ms |
22084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
352 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
119 ms |
22084 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
118 ms |
22100 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
64 ms |
12112 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
32 ms |
5784 KB |
Output is correct |
21 |
Correct |
126 ms |
22052 KB |
Output is correct |
22 |
Correct |
134 ms |
22056 KB |
Output is correct |
23 |
Correct |
130 ms |
22096 KB |
Output is correct |
24 |
Correct |
121 ms |
22100 KB |
Output is correct |
25 |
Correct |
58 ms |
12116 KB |
Output is correct |
26 |
Correct |
57 ms |
12112 KB |
Output is correct |
27 |
Correct |
133 ms |
22100 KB |
Output is correct |
28 |
Correct |
124 ms |
22100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
34 ms |
5776 KB |
Output is correct |
5 |
Correct |
122 ms |
22096 KB |
Output is correct |
6 |
Correct |
132 ms |
22096 KB |
Output is correct |
7 |
Correct |
157 ms |
22100 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
32 ms |
5812 KB |
Output is correct |
10 |
Correct |
122 ms |
22044 KB |
Output is correct |
11 |
Correct |
155 ms |
22096 KB |
Output is correct |
12 |
Correct |
150 ms |
22100 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
59 ms |
5972 KB |
Output is correct |
17 |
Correct |
136 ms |
22292 KB |
Output is correct |
18 |
Correct |
135 ms |
22096 KB |
Output is correct |
19 |
Correct |
135 ms |
22356 KB |
Output is correct |
20 |
Correct |
118 ms |
22040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
352 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
119 ms |
22084 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
118 ms |
22100 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
64 ms |
12112 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
32 ms |
5784 KB |
Output is correct |
21 |
Correct |
126 ms |
22052 KB |
Output is correct |
22 |
Correct |
134 ms |
22056 KB |
Output is correct |
23 |
Correct |
130 ms |
22096 KB |
Output is correct |
24 |
Correct |
121 ms |
22100 KB |
Output is correct |
25 |
Correct |
58 ms |
12116 KB |
Output is correct |
26 |
Correct |
57 ms |
12112 KB |
Output is correct |
27 |
Correct |
133 ms |
22100 KB |
Output is correct |
28 |
Correct |
124 ms |
22100 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
352 KB |
Output is correct |
6 |
Correct |
6 ms |
1372 KB |
Output is correct |
7 |
Correct |
119 ms |
22084 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
118 ms |
22100 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
64 ms |
12112 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
32 ms |
5784 KB |
Output is correct |
21 |
Correct |
126 ms |
22052 KB |
Output is correct |
22 |
Correct |
134 ms |
22056 KB |
Output is correct |
23 |
Correct |
130 ms |
22096 KB |
Output is correct |
24 |
Correct |
121 ms |
22100 KB |
Output is correct |
25 |
Correct |
58 ms |
12116 KB |
Output is correct |
26 |
Correct |
57 ms |
12112 KB |
Output is correct |
27 |
Correct |
133 ms |
22100 KB |
Output is correct |
28 |
Correct |
124 ms |
22100 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |