이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<vector<int>> a;
bool vis[1001];
#define pb push_back
int not_tog[1001], tog[1001];
int findSet(int i, int p[]) { return (i==p[i]?i:p[i]=findSet(p[i],p)); }
bool isSameSet(int i, int j, int p[]) { return findSet(i,p)==findSet(j,p); }
void unionSet(int i, int j, int p[])
{
int x = findSet(i,p), y = findSet(j,p);
if(x==y)return;
p[y]=x;
}
int N;
void dfs(int s, int x)
{
v.pb(s); vis[s]=true;
for(int i = 0; i < N; i++)
if(!vis[i] and a[s][i]==x) dfs(i, x);
}
int construct(vector<vector<int>> p) {
for(auto u : p)
for(auto v : u)
if(v==3)return 0;
N = p.size(), fill(vis,vis+1000,false);
for(int i = 0; i <= N; i++) tog[i]=not_tog[i]=i;
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
if(i!=j and p[i][j]==0)
unionSet(i,j,not_tog);
for(auto u : p)
{
vector<int> x; x.clear();
for(auto v : u) x.pb(v);
a.pb(x);
}
vector<vector<int>> answer;
vector<int> x; x.clear();
for(int j = 0; j < N; j++)x.pb(0);
for(int i = 0; i < N; i++)
answer.pb(x);
for(int i = 0; i < N; i++)
{
if(vis[i])continue; v.clear();
dfs(i, 1);
for(int j = 0; j < v.size()-1; j++)
{
answer[v[j]][v[j+1]]=1;
}
}
fill(vis,vis+1000,false);
for(int i = 0; i < N; i++)
{
if(vis[i])continue; v.clear();
dfs(i, 2); if(v.size()<=1)continue;
if(v.size()<=2)return 0;
for(int j = 0; j < v.size(); j++)
{
answer[v[j]][v[(j+1)%(int)v.size()]]=1;
}
}
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
if(answer[i][j]==1) answer[j][i]=1;
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++){
if(i!=j and answer[i][j]==1)
unionSet(i,j,tog);
}
}
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
if(i!=j and isSameSet(i,j,tog) and isSameSet(i,j,not_tog)) return 0;
build(answer);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:28:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
28 | for(auto u : p)
| ^~~
supertrees.cpp:31:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
31 | N = p.size(), fill(vis,vis+1000,false);
| ^
supertrees.cpp:46:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
46 | for(int i = 0; i < N; i++)
| ^~~
supertrees.cpp:48:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
48 | for(int i = 0; i < N; i++)
| ^~~
supertrees.cpp:50:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
50 | if(vis[i])continue; v.clear();
| ^~
supertrees.cpp:50:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
50 | if(vis[i])continue; v.clear();
| ^
supertrees.cpp:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int j = 0; j < v.size()-1; j++)
| ~~^~~~~~~~~~~~
supertrees.cpp:60:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
60 | if(vis[i])continue; v.clear();
| ^~
supertrees.cpp:60:29: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
60 | if(vis[i])continue; v.clear();
| ^
supertrees.cpp:63:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int j = 0; j < v.size(); j++)
| ~~^~~~~~~~~~
supertrees.cpp:78:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
78 | for(int i = 0; i < N; i++)
| ^~~
supertrees.cpp:81:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
81 | build(answer);
| ^~~~~
# | 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... |