# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
733783 | tigar | 슈퍼트리 잇기 (IOI20_supertrees) | C++14 | 213 ms | 24176 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
typedef long long ll;
vector<int> jedan[1010], dva[1010], nula[1010];
bool check[1010];
vector<int>lin;
vector<int>cc[1010];
int linije[1010], komponente[1010];
int construct(std::vector<std::vector<int>>p)
{
int n=p.size();
int br=1;
for(int i=0; i<n; i++)linije[i]=-1;
for(int i=0; i<n; i++)
{
if(!check[i])
{
check[i]=true;
lin.push_back(i);
linije[i]=i;
bool z=false, g=false;
for(int j=0; j<n; j++)
{
if(!z and p[i][j]!=0)
{
z=true;
if(komponente[j]!=0 and komponente[i]==0){komponente[i]=komponente[j];}
else if(komponente[j]!=0 and komponente[i]!=0 and komponente[i]!=komponente[j])return 0;
else if(komponente[j]==0){komponente[i]=br; g=true; br++;}
cc[komponente[i]].push_back(i);
}
if(p[i][j]==1)
{
if(linije[j]!=-1 and linije[i]!=linije[j])return 0;
linije[j]=i; check[j]=true;
if(komponente[j]!=0 and komponente[j]!=komponente[i])return 0;
komponente[j]=komponente[i];
jedan[i].push_back(j);
}
else if(p[i][j]==2)
{
if(komponente[j]!=0 and komponente[j]!=komponente[i])return 0;
if(!g and komponente[j]==0)return 0;
komponente[j]=komponente[i];
}
else if(p[i][j]==3)return 0;
else if(p[i][j]==0)
{
if(komponente[i]==komponente[j])return 0;
if(linije[i]==linije[j])return 0;
}
}
}
else
{
for(int j=0; j<n; j++)
{
if(p[i][j]!=p[linije[i]][j])return 0;
}
}
}
///ovde pocinje deo za odgovor, njega sredjujem posle
vector<vector<int> > ans(n);
for(int i=0; i<n; i++){ans[i].resize(n, 0);}
for(int i=0; i<lin.size(); i++)
{
for(int j=1; j<jedan[lin[i]].size(); j++)
{
ans[jedan[lin[i]][j]][jedan[lin[i]][j-1]]=1;
ans[jedan[lin[i]][j-1]][jedan[lin[i]][j]]=1;
}
}
for(int i=1; i<=br; i++)
{
for(int j=0; j<cc[i].size(); j++)
{
//cout<<cc[i][j]<<" ";
if(cc[i].size()==2)return 0;
ans[cc[i][j]][cc[i][(j+1)%cc[i].size()]]=1;
ans[cc[i][(j+1)%cc[i].size()]][cc[i][j]]=1;
}
//cout<<endl;
}
for(int i=0; i<n; i++)
{
ans[i][i]=0;
}
//for(int i=0; i<n; i++){for(int j=0; j<n; j++)cout<<ans[i][j]<<" "; cout<<endl;}
build(ans);
return 1;
}
/*int main()
{
int n; cin>>n;
vector<vector<int> >p;
for(int i=0; i<n; i++)
{
vector<int>pp(n);
for(int j=0; j<n; j++)
{
cin>>pp[j];
}
p.push_back(pp);
}
cout<<construct(p);
}/*/
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |