이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
struct ufds{
vector<int> sz, par;
ufds(int n): sz(n, 1), par(n){
iota(par.begin(), par.end(), 0);
}
int find(int a){
return par[a] == a ? a : par[a] = find(par[a]);
}
int unite(int a, int b){
a = find(a), b = find(b);
if(a == b) return 0;
if(sz[a] < sz[b]) swap(a, b);
par[b] = a;
sz[a] += sz[b];
return 1;
}
};
int construct(std::vector<std::vector<int>> p){
int n = p.size();
vector<vector<int>> ans(n, vector<int>(n));
ufds ds(n);
for(int i = 0; i < n; i++){
if(p[i][i] != 1) return 0;
for(int j = 0; j < n; j++){
if(p[i][j] != p[j][i]) return 0;
if(p[i][j] == 3) return 0;
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 1){
ds.unite(i, j);
}else if(p[i][j] == 0){
if(ds.find(i) == ds.find(j)){
return 0;
}
}
}
}
vector<int> rep;
for(int i = 0; i < n; i++){
int p = ds.find(i);
if(i != p){
ans[i][p] = ans[p][i] = 1;
}else{
rep.push_back(i);
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 2){
ds.unite(i, j);
}else if(p[i][j] == 0){
if(ds.find(i) == ds.find(j)){
return 0;
}
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(p[i][j] == 0 && ds.find(i) == ds.find(j)) return 0;
}
}
vector<vector<int>> comp(n);
for(int x: rep){
comp[ds.find(x)].push_back(x);
}
for(int i = 0; i < n; i++){
if(comp[i].size() == 2) return 0;
else if(comp[i].size() >= 3){
for(int j = 0; j < comp[i].size(); j++){
int a = comp[i][j], b = comp[i][(j + 1) % comp[i].size()];
ans[a][b] = ans[b][a] = 1;
}
}
}
build(ans);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:77:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int j = 0; j < comp[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... |