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 N 1005
using namespace std;
int construct(vector<vector<int>> p){
int n = p.size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
answer.push_back(row);
}
vector<bool> vis(n);
for(int i = 0;i<n;i++){
if(!vis[i]){
vector<bool> vis2(n);
vector<bool> cur(n);
vector<int> now;
for(int j = 0;j<n;j++){
if(p[i][j]){
vis[j] = 1;
cur[j] = 1;
now.push_back(j);
}
}
for(auto u:now){
for(int j = 0;j<n;j++){
if(!!p[u][j] != cur[j]){
return 0;
}
}
}
vector<int> circle;
vector<int> par_on_circle(n);
for(auto u:now){
if(vis2[u])continue;
circle.push_back(u);
for(int j = 0;j<n;j++){
if(p[u][j] == 1){
par_on_circle[j] = u;
vis2[j] = 1;
if(u != j){
answer[u][j] = answer[j][u] = 1;
}
}
}
}
for(auto u:now){
for(auto c:now){
if(p[u][c] != 2 - (par_on_circle[u] == par_on_circle[c])){
return 0;
}
}
}
int sz = circle.size();
if(sz != 1){
for(int j = 0;j<sz;j++){
answer[circle[j]][circle[(j+1)%sz]] = answer[circle[(j+1)%sz]][circle[j]] = 1;
}
}
}
}
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... |