이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,int(v.size())) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=1010;
int n,cnt,valid=1,vis[N],ted[N],cmp[N],p[N][N];
vector<int> vec,g[N];
vector<vector<int>> ans;
void add_edge(int u,int v){
//cout<<u<<" -> "<<v<<endl;
ans[u][v]=1;
ans[v][u]=1;
}
int calc(int u,int x){
int res=0;
f(i,0,n) res+=(p[u][i]==x);
return res;
}
void dfs1(int u){
vis[u]=1,cnt++;
ted[cmp[u]]++;
for(auto v : g[u]){
if(vis[v]) continue ;
cmp[v]=cmp[u];
dfs1(v);
eror(2);
add_edge(cmp[u],v);
if(calc(v,1)!=calc(u,1)) valid=0;
}
}
void dfs2(int u){
vis[u]=1;
cnt+=ted[u];
vec.pb(u);
for(auto v : g[u]){
if(vis[v]) continue ;
dfs2(v);
}
}
int construct(vector<vector<int>> _p) {
n=_p.size(),ans=_p;
f(i,0,n) f(j,0,n){
ans[i][j]=0;
p[i][j]=_p[i][j];
if(p[i][j]>2) valid=0;
}
f(i,0,n) f(j,0,n){
if(p[i][j]==1){
g[i].pb(j);
g[j].pb(i);
}
}
f(i,0,n){
if(vis[i]) continue ;
cnt=0;
cmp[i]=i;
dfs1(i);
if(calc(i,1)!=cnt) valid=0;
}
f(i,0,n) vis[i]=0,g[i].clear();
f(i,0,n) f(j,0,n){
if(p[i][j]==2){
g[cmp[i]].pb(cmp[j]);
g[cmp[j]].pb(cmp[i]);
}
}
f(i,0,n){
if(cmp[i]!=i || vis[i]) continue ;
vec.clear(),cnt=0;
dfs2(i);
if(vec.size()>1){
f(j,0,int(vec.size())){
add_edge(vec[j],(j+1==int(vec.size()) ? vec[0] : vec[j+1]));
}
}
if(vec.size()==2){
valid=0;
}
f(u,0,n){
if(vis[cmp[u]]==0) continue ;
if(calc(u,1)+calc(u,2)!=cnt){
valid=0;
}
}
}
if(valid==0) return 0;
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... |