이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
vector<long>parent;
std::vector<std::vector<int> > answer;
long find_set(long x)
{
if(parent[x]==x){
return x;
}
long z=find_set(parent[x]);
parent[x]=z;
return z;
}
void union_set(long x,long z)
{
x=find_set(x);
z=find_set(z);
if(x!=z){
parent[z]=x;
}
}
int construct(std::vector<std::vector<int> > p) {
int n = p.size();
for(long i=0;i<n;i++){
parent.push_back(i);
}
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
bool ok=true;
for(long i=0;i<n;i++){
for(long j=i+1;j<n;j++){
if(p[i][j]==2){
union_set(i,j);
}
}
}
for(long i=0;i<n;i++){
for(long j=i+1;j<n;j++){
if(p[i][j]==0){
if(find_set(i)==find_set(j)){
ok=false;
i=n;
break;
}
}
}
}
vector<vector<long> >v(n);
long x,z;
for(long i=0;i<n;i++){
x=find_set(i);
v[x].push_back(i);
}
for(long i=0;i<n;i++){
x=v[i].size();
if(x>1){
for(long j=0;j<x;j++){
z=v[i][(j+1)%x];
answer[v[i][z]][v[i][j]]=1;
answer[v[i][j]][v[i][z]]=1;
}
}
}
if(ok){
build(answer);
return 1;
}
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... |