이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1010;
struct DSU{
int dsu[mxn],sz[mxn];
DSU(){
iota(dsu,dsu+mxn,0);
fill(sz,sz+mxn,1);
}
int root(int k){
return k == dsu[k]?k:dsu[k] = root(dsu[k]);
}
void onion(int a,int b){
a = root(a),b = root(b);
if(a == b)return;
if(sz[a]<sz[b])swap(a,b);
dsu[b] = a;
sz[a] += sz[b];
}
};
/*
std::vector<std::vector<int>> answer(n,vector<int>(n,0));
build(answer);
return 1;
*/
DSU chain,cyc;
int N;
vector<vector<int>> ans;
vector<vector<int>> tar;
vector<int> v[mxn];
void add_edge(int a,int b){
assert(a != b);
ans[a][b] = ans[b][a] = 1;
}
bool check(){
for(int i = 0;i<N;i++){
for(int j = 0;j<N;j++){
if(tar[i][j] == 0){
if(chain.root(i) == chain.root(j))return false;
}
else if(tar[i][j] == 1){
if(chain.root(i) != chain.root(j))return false;
}
}
}
return true;
}
int construct(std::vector<std::vector<int>> vvv) {
tar = vvv;
N = tar.size();
for(int i = 0;i<N;i++){
for(int j = 0;j<N;j++){
if(tar[i][j] == 1)chain.onion(i,j);
}
}
ans = vector<vector<int>>(N,vector<int>(N,0));
for(int i = 0;i<N;i++){
v[chain.root(i)].push_back(i);
}
for(int i = 0;i<N;i++){
for(int j = 1;j<v[i].size();j++){
add_edge(v[i][j-1],v[i][j]);
}
}
if(!check())return 0;
build(ans);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:70:18: 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<v[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... |