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 <bits/stdc++.h>
using namespace std;
int n;
bool bad=false;
vector<vector<int>> ans;
int viz[1005], viz2[1005];
void addEdge(int x, int y)
{
ans[x][y] = ans[y][x] = 1;
}
void solve(vector<int> &v, vector<vector<int>> &p)
{
vector<int> circle;
for(int i : v)
{
if(!viz2[i])
{
circle.push_back(i);
viz2[i]=true;
for(int j=0;j<n;j++)
if(i != j && p[i][j] == 1)
{
addEdge(i ,j);
viz2[j]=true;
for(int k=0;k<n;k++)
if(p[i][k] != p[j][k])
bad = true;
}
}
}
if(circle.size() > 1)
{
for(int i=1; i<(int)circle.size(); i++)
addEdge(circle[i-1], circle[i]);
if(circle.size() > 2)
addEdge(circle[0], circle.back());
}
}
int construct(vector<vector<int>> p)
{
n=p.size();
ans.resize(n);
for(int i=0;i<n;i++)
ans[i].resize(n);
//cout<<ans.size()<<'\n';
for(int i=0;i<n;i++)
for(int it : p[i])
if(it == 3 )
return 0;
for(int i=0;i<n;i++)
{
if(!viz[i])
{
vector<int> v;
for(int j=0;j<n;j++)
if(p[i][j])
{
v.push_back(j);
viz[j]=true;
}
for(int it : v)
for(int it2 : v)
if(p[it][it2] == 0)
return 0;
for(int it : v)
for(int j=0;j<n;j++)
if(p[it][j] && !p[i][j])
return 0;
solve(v, p);
}
}
if(bad)
return 0;
build(ans);
return 1;
}
# | 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... |