이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
vector<vector<ll> >ans,v,w;
vector<pair<ll,ll> >op;
ll n,p1[1009],p2[1009],id[1009];
ll gp1(ll z)
{
if(p1[z]==z)
return z;
return p1[z]=gp1(p1[z]);
}
ll gp2(ll z)
{
if(p2[z]==z)
return z;
return p2[z]=gp2(p2[z]);
}
void mrg1(ll x,ll y)
{
x=gp1(x),y=gp1(y);
if(x==y)
return;
if(v[y].size()>v[x].size())
swap(x,y);
for(auto z:v[y])
v[x].push_back(z);
}
void mrg2(ll x,ll y)
{
x=gp2(x),y=gp2(y);
if(x==y)
return;
if(w[y].size()>w[x].size())
swap(x,y);
for(auto z:w[y])
w[x].push_back(z);
}
int construct(vector<vector<int> > pp)
{
n=pp.size();
v.resize(n);
w.resize(n);
ans.resize(n);
for(ll i=0; i<n; i++)
ans[i].resize(n);
for(ll i=0; i<n; i++)
p1[i]=p2[i]=i,w[i].push_back(i),v[i]=w[i];
for(ll i=0; i<n; i++)
for(ll j=0; j<n; j++)
{
if(i==j)
continue;
if(pp[i][j]==3)
return 0;
if(pp[i][j]==1)
mrg1(i,j);
else
mrg2(i,j);
}
for(ll i=0; i<n; i++)
{
if(p1[i]==i)
for(ll j=0; j<v[i].size()-1; j++)
op.push_back({v[i][j],v[i][j+1]});
if(p2[i]==i&&w[i].size()>1)
{
for(ll j=0; j<w[i].size()-1; j++)
op.push_back({w[i][j],w[i][j+1]});
op.push_back({w[i][0],w[i].back()});
}
}
for(ll i=0; i<n; i++)
for(ll j=0; j<n; j++)
{
if(pp[i][j]!=0)
continue;
ll x=gp1(x),y=gp1(y);
if(x==y)
return 0;
ll xx=gp2(x),yy=gp2(y);
if(xx==yy)
return 0;
}
for(auto z:op)
ans[z.first][z.second]=ans[z.second][z.first]=1;
build(ans);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:68:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(ll j=0; j<v[i].size()-1; j++)
| ~^~~~~~~~~~~~~~
supertrees.cpp:72:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(ll j=0; j<w[i].size()-1; j++)
| ~^~~~~~~~~~~~~~
supertrees.cpp:12:17: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
12 | return p1[z]=gp1(p1[z]);
| ~~~~~^~~~~~~~~~~
supertrees.cpp:82:25: note: 'y' was declared here
82 | ll x=gp1(x),y=gp1(y);
| ^
supertrees.cpp:12:17: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
12 | return p1[z]=gp1(p1[z]);
| ~~~~~^~~~~~~~~~~
supertrees.cpp:82:16: note: 'x' was declared here
82 | ll x=gp1(x),y=gp1(y);
| ^
# | 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... |