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>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const ll inf = 1e18;
const int mod = 1e9+7;
const int maxn = 1000 + 2;
vector<int> g[maxn];
int x;
int h[maxn], oh[maxn], used[maxn];
bool two[maxn], three[maxn];
bool was[maxn];
void dfs(int v){
h[v] = x;
was[v] = 1;
for(auto i : g[v]){
if(!was[i]){
dfs(i);
}
}
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n);
for(int i = 0; i < n; i++)ans[i].resize(n);
for(int i = 0; i < n; i++){
for(int j = 0; j <= i; j++){
if(i == j){
if(p[i][i] != 1)return 0;
continue;
}
if(p[i][j]){
g[j].pb(i);
g[i].pb(j);
}
if(p[i][j] != p[j][i]){
return 0;
}
}
}
for(int i = 0; i < n; i++){
if(!was[i]){
x = i;
dfs(i);
}
}
for(int i = 0; i < n; i++){
oh[i] = used[i] = -1;
for(int j = 0; j < n; j++){
if(h[i] == h[j] && p[i][j] == 0){
return 0;
}
if(h[i] == h[j]){
if(p[i][j] == 2){
two[h[i]] = 1;
}
else if(p[i][j] == 3){
three[h[i]] = 1;
}
if(two[h[i]] && three[h[i]]){
return 0;
}
}
}
}
vt<int> unq;
for(int i = 0; i < n; i++){
if(oh[i] == -1){
unq.pb(i);
oh[i] = i;
for(auto j : g[i]){
if(p[i][j] == 1){
if(oh[j] != -1){
return 0;
}
oh[j] = i;
ans[i][j] = ans[j][i] = 1;
}
}
}
}
int sz = unq.size();
for(int I = 0; I < sz; I++){
int i = unq[I];
if(used[i] != -1)continue;
used[i] = i;
if(h[i] != i)return 0;
if(!three[i] && !two[i])continue;
bool wt = 0;
if(three[i])wt = 1;
int o = -1, ls = -1, z = -1;
for(int J = 0; J < sz; J++){
int j = unq[J];
if(p[i][j] > 1 && used[j] == -1){
used[j] = i;
if(o == -1){
o = j;
ans[i][o] = ans[o][i] = 1;
}
else {
if(ls == -1)ls = j;
ans[z][j] = ans[j][z] = 1;
z = j;
}
}
else if(p[i][j] > 1)return 0;
}
if(z == -1)return 0;
ans[o][z] = ans[z][o] = 1;
if(wt && z == ls){
return 0;
}
else if(wt){
ans[z][i] = ans[i][z] = 1;
}
}
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... |