This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "supertrees.h"
#include <vector>
#include<stdio.h>
#define pb push_back
const int N = 1005;
using namespace std;
int taken[N], compcnt = 1, n, have1[N], taken2[N];
vector<int>comp[N], idk[N], comp2[N];
vector<vector<int>>p;
bool checkValid()
{
for(int a = 1; a < compcnt; a++)
for(int b = 0; b < comp[a].size(); b++)
for(int c = 0; c < comp[a].size(); c++)
if(p[comp[a][b]][comp[a][c]] == 0 || p[comp[a][b]][comp[a][c]] == 3)
return false;
for(int a = 0; a < n; a++)
for(int b = 0; b < n; b++)
if(p[a][b] > 0 && taken[a] != taken[b])
return false;
return true;
}
int gettype(int i)
{
if(comp[i].size() == 1)
return 3;
int mini = 3;
int maxi = 0;
for(auto a:comp[i])
for(auto b:comp[i])
{
if(a == b)
continue;
mini=min(mini, p[a][b]);
maxi=max(maxi, p[a][b]);
}
if(mini == maxi)
{
if(mini == 1)
return 0;
else
return 1;
}
return 2;
}
int construct(vector<vector<int>> pp) {
p = pp;
n = p.size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
answer.push_back(row);
}
// printf("1\n");
for(int a = 0; a < n; a++)
{
if(taken[a])
continue;
for(int b = 0; b < n; b++)
if(p[a][b])
{
// printf("%d ", b);
comp[compcnt].pb(b);
taken[b] = compcnt;
}
// printf("\n");
compcnt++;
}
// for(int a = 0; a < n; a++)
// printf("%d: %d\n", a, taken[a]);
// printf("2\n");
if(!checkValid())
return 0;
// printf("3\n");
for(int i = 1; i < compcnt; i++)
{
// printf("4\n");
int x = gettype(i);
if(x == 0)
{
for(int a = 1; a < comp[i].size(); a++)
answer[comp[i][a]][comp[i][a - 1]] = answer[comp[i][a - 1]][comp[i][a]] = 1;
}
else if(x == 1)
{
if(comp[i].size() < 3)
return 0;
for(int a = 1; a <= comp[i].size(); a++)
{
int x = comp[i][a % comp[i].size()];
int y = comp[i][a - 1];
answer[x][y] = answer[y][x] = 1;
}
}
else if(x == 2)
{
// printf("here\n");
int cnt = 0;
for(auto a: comp[i])
if(!taken2[a])
{
// printf("%d\n", a);
cnt++;
for(auto b: comp[i])
{
if(p[a][b] == 1)
{
comp2[cnt].pb(b);
taken2[b] = cnt;
}
}
}
if(cnt < 3)
return 0;
// printf("here\n");
for(int a = 1; a <= cnt; a++)
{
for(auto u: comp2[a])
for(auto v: comp2[a])
if(p[u][v] != 1)
return 0;
for(int b = 1; b < comp2[a].size(); b++)
answer[comp2[a][b]][comp2[a][b - 1]] = answer[comp2[a][b - 1]][comp2[a][b]] = 1;
}
for(int a = 2; a <= cnt; a++)
answer[comp2[a][0]][comp2[a - 1][0]] = answer[comp2[a- 1][0]][comp2[a][0]] = 1;
answer[comp2[1][0]][comp2[cnt][0]] = answer[comp2[cnt][0]][comp2[1][0]] = 1;
}
}
build(answer);
// for(int a = 0; a < n; a++)
// for(int b = 0; b < n; b++)
// if(answer[a][b])
// printf("%d %d\n", a, b);
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'bool checkValid()':
supertrees.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int b = 0; b < comp[a].size(); b++)
| ~~^~~~~~~~~~~~~~~~
supertrees.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int c = 0; c < comp[a].size(); c++)
| ~~^~~~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:88:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int a = 1; a < comp[i].size(); a++)
| ~~^~~~~~~~~~~~~~~~
supertrees.cpp:95:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int a = 1; a <= comp[i].size(); a++)
| ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:129:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
129 | for(int b = 1; b < comp2[a].size(); b++)
| ~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |