이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
vector<pair<int,int>>edges;
int n;
int construct(vector<vector<int>> p){
n=(int)p.size();
vector<vector<int>>odp;
for(int i=0;i<n;i++){
vector<int>v;
for(int j=0;j<n;j++){
if(p[i][j]==3)
return 0;
v.push_back(0);
}
odp.push_back(v);
}
bool ifdeleted[n];
for(int i=0;i<n;i++){
ifdeleted[i]=0;
}
for(int i=0;i<n;i++){
if(ifdeleted[i])
continue;
vector<int>same;
for(int j=0;j<n;j++){
if(p[i][j]==1){
if(p[i]==p[j])
same.push_back(j);
else
return 0;
}
}
for(int j=1;j<(int)same.size();j++){
edges.push_back({same[j-1],same[j]});
ifdeleted[same[j]]=1;
for(int k=0;k<n;k++){
p[k][same[j]]=-1;
}
}
}
for(int i=0;i<n;i++){
if(p[i][i]!=-1)
p[i][i]=2;
}
for(int i=0;i<n;i++){
if(ifdeleted[i])
continue;
vector<int>same;
for(int j=0;j<n;j++){
if(p[i][j]==2){
if(p[i]==p[j])
same.push_back(j);
else
return 0;
}
}
//same.push_back(i);
if(same.size()==2)
return 0;
if(same.size()>2)
edges.push_back({same[0],same[(int)same.size()-1]});
for(int j=1;j<(int)same.size();j++){
edges.push_back({same[j-1],same[j]});
ifdeleted[same[j]]=1;
for(int k=0;k<n;k++){
p[k][same[j]]=-1;
}
}
}
for(int i=0;i<(int)edges.size();i++){
//cout<<edges[i].first<<" "<<edges[i].second<<"\n";
odp[edges[i].first][edges[i].second]=1;
odp[edges[i].second][edges[i].first]=1;
}
build(odp);
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... |