#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Answer gives possible 0 while actual possible 1 |
2 |
Halted |
0 ms |
0 KB |
- |