이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
const int mxN = 1002;
int par[mxN];
void init(int n){
for(int i = 0; i <= n; i++)
par[i] = i;
}
int find(int x){
if(par[x]!=x)
return par[x] = find(par[x]);
return par[x];
}
void merge(int x, int y){
x = find(x);
y = find(y);
if(x==y)
return;
par[x]=y;
}
int construct(vector<vector<int>> p){
for(auto x : p){
for(auto y: x)
if(y==3)
return 0;
}
int n = p.size();
vector<vector<int>>ans(n,vector<int>(n,0)),comp(n,vector<int>()),tree(n,vector<int>());
init(n);
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j])
merge(i,j);
}
}
for(int i = 0; i < n; i++)
comp[find(i)].push_back(i);
init(n);
for(int i = 0; i < n; i++){
for(int c1 : comp[i]){
for(int c2 : comp[i]){
if(p[c1][c2]==0)
return 0;
else if(p[c1][c2]==1)
merge(c1,c2);
}
}
vector<int>cycle;
for(int x : comp[i]){
if(find(x)==x)
cycle.push_back(x);
tree[find(x)].push_back(x);
}
if(cycle.size()==2)
return 0;
if(cycle.size()==1)
continue;
for(int j=0;j<cycle.size();j++){
int x = (j+1==cycle.size()?0:j+1);
ans[cycle[j]][cycle[x]]=1;
ans[cycle[x]][cycle[j]]=1;
}
}
for(int i = 0; i < n; i++){
if(tree[i].size()==0)
continue;
int repn = tree[i][0];
for(int j = 1; j < tree[i].size(); j++){
ans[repn][tree[i][j]]=1;
ans[tree[i][j]][repn]=1;
}
}
build(ans);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int j=0;j<cycle.size();j++){
| ~^~~~~~~~~~~~~
supertrees.cpp:61:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | int x = (j+1==cycle.size()?0:j+1);
| ~~~^~~~~~~~~~~~~~
supertrees.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int j = 1; j < tree[i].size(); j++){
| ~~^~~~~~~~~~~~~~~~
# | 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... |