이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"supertrees.h"
#include<bits/stdc++.h>
#ifdef EVAL
#else
#include"grader.cpp"
#endif
using namespace std;
int par[1005];
bool vis[1005];
vector<int>st[1005];
int fin(int v){
return v==par[v]?v:par[v]=fin(par[v]);
}
void unite(int x,int y){
x=fin(x);
y=fin(y);
if(x!=y){
if(st[x].size()<st[y].size())swap(x,y);
st[x].insert(st[x].end(),st[y].begin(),st[y].end());
st[y].clear();
par[y]=x;
}
}
int construct(vector<vector<int>>p){
int n=p.size(),i,j;
for(i=0;i<n;i++)par[i]=i,st[i].push_back(i);
vector<vector<int>>v(n,vector<int>(n,0));
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(p[i][j]==3)return 0;
if(p[i][j])unite(i,j);
}
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if((!p[i][j]&&fin(i)==fin(j))||(p[i][j]&&fin(i)!=fin(j)))return 0;
for(i=0;i<n;i++)
if(!st[i].empty()){
vector<int>comp;
for(int vv:st[i]){
if(!vis[vv]){
vis[vv]=1;
for(int to:st[vv]){
if(vv!=to&&p[vv][to]==1&&!vis[to]){
vis[to]=1;
v[vv][to]=1;
v[to][vv]=1;
}
}
comp.push_back(vv);
}
}
for(int j=1;j<comp.size();j++)v[comp[j]][comp[j-1]]=v[comp[j-1]][comp[j]]=1;
if(comp.size()!=1)v[comp[0]][comp.back()]=v[comp.back()][comp[0]]=1;
}
build(v);
return 1;
}
/*
4
1 1 2 2
1 1 2 2
2 2 1 2
2 2 2 1
*/
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int j=1;j<comp.size();j++)v[comp[j]][comp[j-1]]=v[comp[j-1]][comp[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... |