이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int pad[2000];
void init(int x){
for(int i=0;i<=x;i++){
pad[i]=i;
}
}
int findset(int i){
if(pad[i]==i)return i;
return pad[i]=findset(pad[i]);
}
bool issameset(int i,int j){
return findset(pad[i])==findset(pad[j]);
}
void unionset(int i,int j){
pad[i]=pad[findset(j)];
}
int construct(vector<vector<int>> p) {
int n = p.size();
init(n);
vector<vector<int>> answer;
for(int i=0;i<n;i++){
answer.push_back(vector<int>(n,0));
}
int cnt=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j]==1)cnt++;
}
}
int sw=1;
if(cnt==n*n){
//cout<<123<<endl;
for(int i=0;i<n-1;i++){
answer[i][i+1]=1;
answer[i+1][i]=1;
}
}
else{
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j]==1){
if(!issameset(i,j)){unionset(i,j);
answer[i][j]=1;
answer[j][i]=1;
}
}
}
}/*
for(int i=0;i<n;i++){
cout<<findset(i)<<" ";
}
cout<<endl;*/
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(p[i][j]==1){
if(issameset(pad[i],pad[j])){}
else sw=0;
//if(sw==0)cout<<i<<" gg "<<j<<endl;
}
else{
if(issameset(i,j))sw=0;
//if(sw==0)cout<<i<<" gg1 "<<j<<endl;
}
}
}
/*cout<<sw<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<answer[i][j]<<" ";
}
cout<<endl;
}*/
}
if(sw){
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... |