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;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#ifdef dremix
#define p(x) cerr<<#x<<" = "<<x<<endl;
#define p2(x,y) cerr<<#x<<" , "<<#y<<" = "<<x<<" , "<<y<<endl;
#define pv(x) cerr<<#x<<" = {";for(auto v : x)cerr<<x<<", ";cerr<<"}"<<endl;
#else
#define p(x) {}
#define p2(x,y) {}
#define pv(x) {}
#endif
const ll INF = 2e18+5;
const int MOD = 1e9+7;
const int N = 1005;
vector<vector<int> > ans;
int v[N];
vector<vector<vector<int> > > a(N,vector<vector<int> >(3,vector<int>()));
int nn;
bool flag = true;
vector<int> par(N),siz(N,1);
vector<vector<int> > g(N);
int find(int x){
return (par[x] == x) ? x : par[x] = find(par[x]);
}
bool join(int x, int y){
x = find(x);
y = find(y);
if(x == y)return false;
if(g[y].size() > g[x].size())swap(x,y);
siz[x] += siz[y];
par[y] = x;
for(auto v : g[y])g[x].push_back(v);
g[y].clear();
return true;
}
int construct(std::vector<std::vector<int>> p) {
int i,j,n = p.size();
ans.assign(n,vector<int>(n,0));
for(i=0;i<n;i++){
g[i].push_back(i);
for(j=0;j<n;j++){
if(p[i][j] == 3)return 0;
a[i][p[i][j]].push_back(j);
}
}
iota(all(par),0);
for(i=0;i<n;i++){
if(v[i]){
continue;
}
//vector<int> chk;
//chk.push_back(i);
int x = i;
v[i] = true;
for(auto j : a[i][1]){
join(i,j);
//chk.push_back(j);
ans[x][j] = ans[j][x] = 1;
x = j;
v[j] = true;
}
for(int k=0;k<n;k++){
bool ok = true;
int need = p[i][k];
for(auto j : g[find(i)]){
if(j == k)continue;
if(p[j][k] != need){
ok = false;
break;
}
}
if(!ok){
flag = false;
break;
}
}
}
if(!flag)return 0;
fill(all(siz),1);
for(i=0;i<n;i++){
for(auto x : a[i][2]){
if(find(i) == find(x))continue;
for(auto v1 : g[find(x)]){
if(p[i][v1] != 2){
flag = false;
break;
}
}
if(!flag)break;
ans[i][x] = ans[x][i] = 1;
join(i,x);
}
}
for(i=0;i<n;i++){
if(siz[find(i)] == 2)flag = false;
}
if(!flag)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... |