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 <vector>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
const int MAX = 1002;
int link[MAX];
inline int seek(int x){
if(x == link[x]) return x;
return link[x] = seek(link[x]);
}
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++) link[i] = i;
int f = 0;
bool flag = 1;
for(auto i: p){
int a = seek(f);
for(int j = 0; j < n; j++){
if(f!=j and i[j] == 1) flag = 0;
if(i[j] != 0){
int b = seek(j);
link[b] = a;
}
}
f++;
}
vector<int> cc[MAX];
for(int i = 0; i < n; i++){
cc[ link[i] ].push_back(i);
}
int mat[n+1][n+1];
memset(mat,0,sizeof(mat));
bool good = 1;
for(int i = 0; i < n; i++){
int sz = (int)(cc[i].size());
for(int j = 0; j < sz-1; j++){
mat[ cc[i][j] ][ cc[i][j+1] ] = 1;
mat[ cc[i][j+1] ][ cc[i][j] ] = 1;
}
if(flag and sz == 2){
good = 0;
}
if(flag and sz > 2){
mat[ cc[i][0] ][ cc[i][ sz-1 ] ] = 1;
mat[ cc[i][ sz-1 ] ][ cc[i][0] ] = 1;
}
}
for(int i = 0; i < n; i++){
vector<int> asd;
for(int j = 0; j < n; j++){
asd.push_back(mat[i][j]);
}
answer.push_back(asd);
}
bool ok = 1;
f = 0;
for(auto i: p){
for(int j = 0; j < n; j++){
if(i[j] == 0 and link[f] == link[j]){
ok = 0;
break;
}
}
f++;
if(!ok) break;
}
if(ok and good){
build(answer);
return 1;
}
else return 0;
}
# | 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... |