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