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;
typedef int ll;
vector<vector<ll> >v,w;
vector<pair<ll,ll> >op;
ll n,p[1009],id[1009];
ll gp(ll z)
{
if(p[z]==z)
return z;
return p[z]=gp(p[z]);
}
void mrg(ll x,ll y,ll k)
{
if(w[y].size()>w[x].size())
swap(x,y);
p[y]=x;
if(k==0)
return;
for(auto z:w[y])
w[x].push_back(z);
id[x]=k;
}
int construct(vector<vector<int> > pp)
{
n=pp.size();
v.resize(n);
w.resize(n);
for(ll i=0; i<n; i++)
v[i].resize(n);
for(ll i=0; i<n; i++)
p[i]=i,w[i].push_back(i);
for(ll i=0; i<n; i++)
for(ll j=0; j<n; j++)
{
if(pp[i][j]<2)
continue;
ll x=gp(i),y=gp(j);
if(x==y)
continue;
if(id[x]*id[y]==6)
return 0;
mrg(x,y,pp[i][j]);
}
for(ll i=0; i<n; i++)
if(p[i]==i)
{
if(id[i]==3)
{
if(w[i].size()<4)
return 0;
for(ll j=0; j<w[i].size()-1; j++)
op.push_back({w[i][j],w[i][j+1]});
op.push_back({w[i][0],w[i].back()});
op.push_back({w[i][1],w[i].back()});
}
else if(id[i]==2)
{
if(w[i].size()<3)
return 0;
for(ll j=0; j<w[i].size()-1; j++)
op.push_back({w[i][j],w[i][j+1]});
op.push_back({w[i][0],w[i].back()});
}
}
for(ll i=0; i<n; i++)
for(ll j=0; j<n; j++)
{
if(pp[i][j]!=1||i==j)
continue;
ll x=gp(x),y=gp(y);
if(w[x].size()>1&&w[y].size()>1)
return 0;
mrg(x,y,0);
op.push_back({i,j});
}
for(ll i=0; i<n; i++)
for(ll j=0; j<n; j++)
{
if(pp[i][j])
continue;
ll x=gp(i),y=gp(j);
if(x==y)
return 0;
}
for(auto z:op)
v[z.first][z.second]=v[z.second][z.first]=1;
build(v);
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:56:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(ll j=0; j<w[i].size()-1; j++)
| ~^~~~~~~~~~~~~~
supertrees.cpp:65:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(ll j=0; j<w[i].size()-1; j++)
| ~^~~~~~~~~~~~~~
supertrees.cpp:12:16: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
12 | return p[z]=gp(p[z]);
| ~~~~^~~~~~~~~
supertrees.cpp:75:24: note: 'y' was declared here
75 | ll x=gp(x),y=gp(y);
| ^
supertrees.cpp:12:16: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
12 | return p[z]=gp(p[z]);
| ~~~~^~~~~~~~~
supertrees.cpp:75:16: note: 'x' was declared here
75 | ll x=gp(x),y=gp(y);
| ^
# | 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... |