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 <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#include "supertrees.h"
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a[2005][2005],ans[2005][2005],par[2005],siz[2005];
vector<ll>v[2005];
ll caut(ll x){
if(x==par[x]){
return x;
}else return par[x]=caut(par[x]);
}
void uni(ll x,ll y){
x=caut(x);
y=caut(y);
ans[x][y]=1;
ans[y][x]=1;
if(siz[x]>siz[y]){
swap(x,y);
}
siz[y]+=siz[x];
par[x]=y;
}
int construct(vector<vector<int>>p){
n=p[0].size();
for(ll i=0;i<n;i++)
{
for(ll j=0;j<n;j++)
{
a[i][j]=p[i][j];
}
}
for(ll i=0;i<n;i++)
{
par[i]=i;
}
for(ll i=0;i<n;i++)
{
for(ll j=i+1;j<n;j++)
{
if(a[i][j]){
if(caut(i)!=caut(j)){
uni(i,j);
}
}
}
}
for(ll i=0;i<n;i++)
{
for(ll j=i+1;j<n;j++)
{
if(a[i][j]==0){
if(caut(i)==caut(j)){
return 0;
}
}
}
}
for(ll i=0;i<n;i++)
{
v[caut(i)].pb(i);
}
for(ll i=0;i<n;i++)
{
ll x=v[i].size();
if(x<=1){
continue;
}
for(ll j=1;j<v[i].size();j++)
{
ans[v[i][j-1]][v[i][j]]=1;
ans[v[i][j]][v[i][j-1]]=1;
}
if(a[v[i][0]][v[i][1]]==2){
if(x==2){
return 0;
}
ans[v[i][0]][v[i][x-1]]=1;
ans[v[i][x-1]][v[i][0]]=1;
}
}
/*
for(ll i=0;i<n;i++){
for(ll j=0;j<n;j++)
{
cout<<ans[i][j]<<' ';
}
cout<<endl;
}
*/
vector<vector<int>>res;
res.resize(n);
for(ll i=0;i<n;i++)
{
for(ll j=0;j<n;j++)
{
res[i].pb(ans[i][j]);
}
}
build(res);
return 1;
}
/*
int32_t main(){
CODE_START;
*/
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:88:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(ll j=1;j<v[i].size();j++)
| ~^~~~~~~~~~~~
# | 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... |