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];
ll gp(ll z)
{
if(p[z]==z)
return z;
return p[z]=gp(p[z]);
}
void mrg(ll x,ll y)
{
if(w[y].size()>w[x].size())
swap(x,y);
p[y]=x;
for(auto z:w[y])
w[x].push_back(z);
}
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(i==j||pp[i][j]==0)
continue;
ll x=gp(i),y=gp(j);
if(x==y)
continue;
mrg(x,y);
}
for(ll i=0; i<n; i++)
{
if(p[i]!=i||w[i].size()==1)
continue;
if(w[i].size()==2)
return 0;
for(ll k=0; k<w[i].size()-1; k++)
op.push_back({w[i][k],w[i][k+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])
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:50:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(ll k=0; k<w[i].size()-1; k++)
| ~^~~~~~~~~~~~~~
# | 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... |