이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
const int inf=1e9;
void merge(int i,int j,vector<int>& id,vector<vector<int>>& group){
if(id[i]!=id[j]){
int a=id[i],b=id[j];
if(group[a].size()>group[b].size()) swap(a,b);
for(int&x:group[a]) group[b].push_back(x);
for(int&x:group[a]) id[x]=b;
group[a].clear();
}
return ;
}
int construct(vector<vector<int>> p){
int n=p.size();
vector<vector<int>> group(n),grp(n);
vector<int> id(n),rid(n);
for(int i=0;i<n;i++){
id[i]=i; rid[i]=i;
group[i].push_back(i);
grp[i].push_back(i);
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i!=j){
if(p[i][j]==2)
merge(i,j,id,group);
}
}
}
vector<vector<int>> answer(n,vector<int>(n,0));
for(int i=0;i<n;i++){
for(int&x:group[i]){
for(int&y:group[i])
if(x!=y&&p[x][y]!=2){
cout << x << " " << y << endl ;
for(int&x:group[i]) cout << x << " " ;
return 0;
}
}
for(int j=0;j+1<group[i].size();j++) answer[group[i][j]][group[i][j+1]]=answer[group[i][j+1]][group[i][j]]=1;
}
/*for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i!=j&&group[id[i]].size()==1&&group[id[j]].size()==1&&p[i][j]==1){
merge(i,j,rid,grp);
}
}
}
for(int i=0;i<n;i++){
for(int&x:grp[i])
for(int&y:grp[i])
if(p[x][y]!=1)
return 0;
}
for(int i=0;i<n;i++){
for(int j=0;j+1<grp[i].size();j++)
answer[grp[i][j]][grp[i][j+1]]=answer[grp[i][j]][grp[i][j+1]]=1;
}
vector<int> cnt(n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(group[id[i]].size()==1&&group[id[j]].size()==2&&p[i][j]==1){
if(cnt[rid[i]]) return 0;
cnt[rid[i]]=1;
answer[rid[i]][id[j]]=answer[id[j]][rid[i]]=1;
for(int&x:grp[rid[i]])
for(int&y:group[id[j]])
if(p[x][y]==0)
return 0;
}
}
}*/
construct(answer);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:43:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j=0;j+1<group[i].size();j++) answer[group[i][j]][group[i][j+1]]=answer[group[i][j+1]][group[i][j]]=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... |