이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
int visited[2000], hi[1000000];
vector<vector<int> > adjlist;
int coun=1;
void dfs(int s){
visited[s]=coun;
for(int i=0; i<adjlist[s].size(); i++){
int v=adjlist[s][i];
if(visited[v]==0)
dfs(v);
}
}
int construct(vector<vector<int> > p) {
int n = p.size();
adjlist.assign(n+1, vector<int>());
bool is=false;
set<int> si;
map<int, int> u;
for(int i=0; i<n; i++){
bool zxcv=true;
for(int j=0; j<n; j++){
if(p[i][j] && i!=j){
si.insert(p[i][j]);
if(p[i][j]==1)
zxcv=false;
else
u[i]++, u[j]++;
adjlist[i].push_back(j);
adjlist[j].push_back(i);
}
if(p[i][j]==2)
is=true;
}
if(zxcv)
hi[i]=1;
}
for(int i=0; i<n; i++){
if(visited[i]==0){
dfs(i);
coun++;
}
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(visited[i]==visited[j] && p[i][j]==0)
return 0;
}
}
vector<vector<int> > answer;
answer.assign(n, vector<int>());
for(int i=0; i<n; i++)
answer[i].assign(n, 0);
map<int, vector<int> > mp;
for(int i=0; i<n; i++)
mp[visited[i]].push_back(i);
if(si.size()<=1){
for(auto x:mp){
for(int i=1; i<x.second.size(); i++){
answer[x.second[i-1]][x.second[i]]=1;
answer[x.second[i]][x.second[i-1]]=1;
}
if(is){
if(x.second.size()==1)
continue;
if(x.second.size()==2)
return 0;
answer[x.second[0]][x.second[x.second.size()-1]]=1;
answer[x.second[x.second.size()-1]][x.second[0]]=1;
}
}
}
else{
for(auto x:mp){
vector<int> vi;
int asdf, hi1=x.second.size();
for(int i=0; i<hi1; i++){
if(hi[x.second[i]])
vi.push_back(x.second[i]);
}
asdf=vi.size();
for(int i=0; i<hi1; i++)
if(!hi[x.second[i]] && u[x.second[i]]==asdf)
vi.push_back(x.second[i]);
for(int i=0; i<hi1; i++)
if(!hi[x.second[i]] && !u[x.second[i]]==asdf)
vi.push_back(x.second[i]);
hi1=vi.size();
for(int i=1; i<hi1; i++){
answer[vi[i-1]][vi[i]]=1;
answer[vi[i]][vi[i-1]]=1;
}
if(asdf>1){
answer[vi[0]][vi[asdf]]=1;
answer[vi[asdf]][vi[0]]=1;
}
}
}
build(answer);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:9:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | for(int i=0; i<adjlist[s].size(); i++){
| ~^~~~~~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:60:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int i=1; i<x.second.size(); i++){
| ~^~~~~~~~~~~~~~~~
supertrees.cpp:87:43: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
87 | if(!hi[x.second[i]] && !u[x.second[i]]==asdf)
| ^~
supertrees.cpp:87:28: note: add parentheses around left hand side expression to silence this warning
87 | if(!hi[x.second[i]] && !u[x.second[i]]==asdf)
# | 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... |