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"
#define MAXN 1009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int vis[MAXN];
vector<int>adj[MAXN];
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}int mx=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(i!=j)
umax(mx,p[i][j]);
if(mx==3)
return 0;
if(mx==0){
build(answer);
return 1;
}
vector<int>a; int cnt=0;
for(int i=0;i<n;i++)
if(!vis[i]){
a.clear();
vis[i]=++cnt;a.pb(i);
for(int j=i+1;j<n;j++)
if(p[i][j]){
if(vis[j])
return 0;
if(p[i][j]==2){
int who=-1;
tr(it,a)
if(p[*it][j]==1){
who=*it;
break;
}
if(who==-1)
a.pb(j);
else{
assert(who!=j);
answer[who][j]=answer[j][who]=1,adj[who].pb(j);
}
}
else
answer[i][j]=answer[j][i]=1,adj[i].pb(j);
vis[j]=cnt;
}
tr(it,a){
for(int j=0;j<int(adj[*it].size());j++)
for(int k=j+1;k<int(adj[*it].size());k++)
if(p[adj[*it][j]][adj[*it][k]]!=1)
return 0;
}
for(int j=0;j<int(a.size());j++)
for(int k=j+1;k<int(a.size());k++)
for(int jj=0;jj<int(adj[a[j]].size());jj++)
for(int kk=0;kk<int(adj[a[k]].size());kk++)
if(p[adj[a[j]][jj]][adj[a[k]][kk]]!=2)
return 0;
if(int(a.size())==1)
continue;
if(int(a.size())==2)
return 0;
for(int j=0;j<int(a.size());j++)
answer[a[j]][a[(j+1)%int(a.size())]]=answer[a[(j+1)%int(a.size())]][a[j]]=1;
}
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if((vis[i]==vis[j] and !p[i][j]) or (p[i][j] and vis[i]!=vis[j]))
return 0;
build(answer);
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... |