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 <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef long long ll;
vector<int> jedan[1010], dva[1010], nula[1010];
bool check[1010];
vector<int>lin;
vector<int>cc[1010];
bool provera(int x, std::vector<std::vector<int>>p, int cmp)
{
lin.push_back(x);
cc[cmp].push_back(x);
int n=p.size();
for(int i=0; i<jedan[x].size(); i++)
{
if(check[jedan[x][i]])continue;
check[jedan[x][i]]=true;
if(jedan[x].size()!=jedan[jedan[x][i]].size())return false;
for(int j=0; j<jedan[x].size(); j++)
{
if(jedan[x][j]!=jedan[jedan[x][i]][j])return false;
}
}
for(int i=0; i<dva[x].size(); i++)
{
if(check[dva[x][i]])continue;
check[dva[x][i]]=true;
if(nula[x].size()!=nula[dva[x][i]].size())return false;
for(int j=0; j<nula[x].size(); j++)
{
if(nula[x][j]!=nula[dva[x][i]][j])return false;
}
if(!provera(dva[x][i], p, cmp))return false;
}
return true;
}
int construct(std::vector<std::vector<int>>p)
{
int n=p.size();
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(p[i][j]==1)jedan[i].push_back(j);
else if(p[i][j]==2)dva[i].push_back(j);
else if(p[i][j]==3)return 0;
else nula[i].push_back(j);
}
}
for(int i=0; i<n; i++)
{
sort(jedan[i].begin(), jedan[i].end());
sort(dva[i].begin(), dva[i].end());
sort(nula[i].begin(), nula[i].end());
}
int br=1;
for(int i=0; i<n; i++)
{
if(check[i])continue;
if(!provera(i, p, br))return 0;
br++;
}
vector<vector<int> > ans(n);
for(int i=0; i<n; i++){ans[i].resize(n, 0);}
for(int i=0; i<lin.size(); i++)
{
for(int j=1; j<jedan[lin[i]].size(); j++)
{
ans[jedan[lin[i]][j]][jedan[lin[i]][j-1]]=1;
ans[jedan[lin[i]][j-1]][jedan[lin[i]][j]]=1;
}
}
for(int i=1; i<br; i++)
{
for(int j=0; j<cc[i].size(); j++)
{
//cout<<cc[i][j]<<" ";
if(cc[i].size()==2)return 0;
ans[cc[i][j]][cc[i][(j+1)%cc[i].size()]]=1;
ans[cc[i][(j+1)%cc[i].size()]][cc[i][j]]=1;
}
//cout<<endl;
}
for(int i=0; i<n; i++)
{
ans[i][i]=0;
}
//for(int i=0; i<n; i++){for(int j=0; j<n; j++)cout<<ans[i][j]<<" "; cout<<endl;}
build(ans);
return 1;
}
/*int main()
{
int n; cin>>n;
vector<vector<int> >p;
for(int i=0; i<n; i++)
{
vector<int>pp(n);
for(int j=0; j<n; j++)
{
cin>>pp[j];
}
p.push_back(pp);
}
cout<<construct(p);
}
*/
Compilation message (stderr)
supertrees.cpp: In function 'bool provera(int, std::vector<std::vector<int> >, int)':
supertrees.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=0; i<jedan[x].size(); i++)
| ~^~~~~~~~~~~~~~~~
supertrees.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int j=0; j<jedan[x].size(); j++)
| ~^~~~~~~~~~~~~~~~
supertrees.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i=0; i<dva[x].size(); i++)
| ~^~~~~~~~~~~~~~
supertrees.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int j=0; j<nula[x].size(); j++)
| ~^~~~~~~~~~~~~~~
supertrees.cpp:16:9: warning: unused variable 'n' [-Wunused-variable]
16 | int n=p.size();
| ^
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:69:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=0; i<lin.size(); i++)
| ~^~~~~~~~~~~
supertrees.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int j=1; j<jedan[lin[i]].size(); j++)
| ~^~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(int j=0; j<cc[i].size(); j++)
| ~^~~~~~~~~~~~~
# | 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... |