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;
#define sz(x) (int)x.size()
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define lowb(x) (x&(-x))
#define ALL(_x) _x.begin(),_x.end()
#define pii pair<int,int>
#define f first
#define s second
#define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end())
#define MNTO(x,y) x=min(x,y)
const int maxn=1e3+5;
namespace {
struct uf{
int par[maxn];
void init(int n){
REP(i,n) par[i]=i;
}
int find(int u){
if(par[u]==u) return u;
return par[u]=find(par[u]);
}
void merge(int a,int b){
a=find(a),b=find(b);
if(a==b) return;
par[a]=b;
}
}a,b;
vector<int> cmp[maxn],ln[maxn];
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n,vector<int>(n));
REP(i,n){
REP(j,n){
if(p[i][j]==3){
return 0;
}
}
if(p[i][i]!=1){
return 0;
}
}
a.init(n),b.init(n);
REP(i,n){
REP(j,n){
if(p[i][j]){
a.merge(i,j);
}
}
}
REP(i,n){
cmp[a.find(i)].pb(i);
}
REP(i,n){
if(!sz(cmp[i])) continue;
for(int x:cmp[i]){
for(int y:cmp[i]){
if(p[x][y]==0){
return 0;
}
if(p[x][y]==1){
b.merge(x,y);
}
}
}
for(int x:cmp[i]){
for(int y:cmp[i]){
if(p[x][y]==2 and b.find(x)==b.find(y)){
return 0;
}
}
}
vector<int> cyc;
for(int x:cmp[i]){
cyc.pb(b.find(x));
ln[b.find(x)].pb(x);
}
SORT_UNIQUE(cyc);
if(sz(cyc)==2){
return 0;
}
if(sz(cyc)>1){
int k=sz(cyc);
REP(j,k){
ans[cyc[j]][cyc[(j+1)%k]]=ans[cyc[(j+1)%k]][cyc[j]]=1;
}
}
for(int x:cmp[i]){
for(int a:ln[x]){
for(int b:ln[x]){
if(p[a][b]!=1){
return 0;
}
}
}
int pv=-1;
for(int y:ln[x]){
if(pv!=-1) ans[pv][y]=ans[y][pv]=1;
pv=y;
}
}
}
build(ans);
return 1;
}
# | 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... |