# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1078821 | Muhammad_Aneeq | Connecting Supertrees (IOI20_supertrees) | C++17 | 164 ms | 23928 KiB |
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 <vector>
#include <iostream>
using namespace std;
int const MAXN=1000;
void build(vector<vector<int>> b);
int construct(vector<vector<int>> p)
{
int n=p.size();
bool subt1=1,subt2=1,subt3=1,subt4=1;
for (int i=0;i<n;i++)
{
for (int j=i+1;j<n;j++)
{
if (p[i][j]!=1)
subt1=0;
if (p[i][j]>1)
subt2=0;
if (p[i][j]==1)
subt3=0;
if (p[i][j]>2)
subt4=0;
}
}
if (subt1)
{
vector<vector<int>>b(n,vector<int>(n));
for (int i=1;i<n;i++)
b[0][i]=b[i][0]=1;
build(b);
return 1;
}
if (subt2)
{
bool vis[n]={};
int head[n]={};
vector<vector<int>>b(n,vector<int>(n));
for (int i=0;i<n;i++)
{
if (!vis[i])
{
vis[i]=1;
head[i]=i;
for (int j=0;j<n;j++)
{
if (vis[j])
continue;
if (p[i][j])
{
vis[j]=1;
b[i][j]=b[j][i]=1;
head[j]=i;
}
}
}
}
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
if (p[i][j]&&head[i]!=head[j])
return 0;
if (p[i][j]==0&&head[i]==head[j])
return 0;
}
}
build(b);
return 1;
}
if (subt3)
{
bool vis[n]={};
int head[n]={};
vector<vector<int>>b(n,vector<int>(n));
for (int i=0;i<n;i++)
{
if (!vis[i])
{
vector<int>z;
for (int j=0;j<n;j++)
{
if (p[i][j])
z.push_back(j);
}
if (z.size()==1)
{
head[i]=i;
continue;
}
if (z.size()==2)
return 0;
for (int j=0;j<z.size();j++)
{
vis[z[j]]=1;
head[z[j]]=i;
b[z[j]][z[(j+1)%z.size()]]=b[z[(j+1)%z.size()]][z[j]]=1;
}
}
}
for (int i=0;i<n;i++)
{
for (int j=i+1;j<n;j++)
{
if (p[i][j]&&head[i]!=head[j])
return 0;
if (p[i][j]==0&&head[i]==head[j])
return 0;
}
}
build(b);
return 1;
}
bool seen[n]={};
int head[n]={};
bool vis[n]={};
vector<vector<int>>b(n,vector<int>(n,0));
for (int i=0;i<n;i++)
{
if (!seen[i])
{
seen[i]=1;
head[i]=i;
for (int j=0;j<n;j++)
{
if (seen[j])
{
if (i!=j&&p[i][j]==1)
return 0;
continue;
}
if (p[i][j]==1)
{
seen[j]=1;
b[i][j]=b[j][i]=1;
head[j]=i;
}
}
}
}
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
if (p[i][j]==1&&head[i]!=head[j])
return 0;
if (p[i][j]!=1&&head[i]==head[j])
return 0;
}
}
for (int i=0;i<n;i++)
{
if (vis[head[i]])
continue;
vector<int>x;
for (int j=0;j<n;j++)
{
if (p[i][j]&&!vis[head[j]])
{
x.push_back(head[j]);
vis[head[j]]=1;
}
}
if (x.size()==2)
return 0;
if (x.size()<2)
continue;
int pa=head[i];
for (int j=0;j<x.size();j++)
{
int u=x[j],v=x[(j+1)%x.size()];
head[u]=head[v]=pa;
b[u][v]=b[v][u]=1;
}
}
for (int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
int u=head[head[i]],v=head[head[j]];
if (u==v)
continue;
if (p[i][j]!=2&&b[u][v])
return 0;
if (p[i][j]==2&&!b[u][v])
return 0;
}
}
build(b);
return 1;
}
Compilation message (stderr)
# | 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... |