이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <vector>
#include <stdio.h>
using namespace std;
vector < int > how[1005];
vector < int > how2[1005];
vector < int > cycle;
int Father[1005];
int Find(int here)
{
if(Father[here]==here) return here;
Father[here]=Find(Father[here]);
return Father[here];
}
int construct(vector < vector< int > > p)
{
int n=p.size(),i,j,k,m;
vector< vector<int> > answer;
vector< int > row;
for(i=0;i<n;i++) row.push_back(0);
for(i=0;i<n;i++)
{
answer.push_back(row);
Father[i]=i;
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(p[i][j]==0&&Find(i)==Find(j)) return 0;
else if(p[i][j]) Father[Find(i)]=Find(j);
}
}
for(i=0;i<n;i++) how[Find(i)].push_back(i);
for(i=0;i<n;i++)
{
m=how[i].size();
if(m<=1) continue;
for(auto j:how[i]) Father[j]=j;
for(j=0;j<m;j++)
{
for(k=0;k<m;k++)
{
if(Find(how[i][j])==Find(how[i][k])&&p[how[i][j]][how[i][k]]==2) return 0;
else if(p[how[i][j]][how[i][k]]==1) Father[Find(how[i][j])]=Find(how[i][j]);
}
}
for(auto j:how[i]) how2[Find(j)].push_back(j);
cycle.clear();
for(auto j:how[i])
{
m=how2[j].size();
if(m==0) continue;
for(j=1;j<m;j++)
{
answer[how2[i][j-1]][how2[i][j]]=1;
answer[how2[i][j]][how2[i][j-1]]=1;
}
cycle.push_back(how2[i][0]);
}
m=cycle.size();
if(m==1) continue;
for(j=1;j<m;j++)
{
answer[how[i][j-1]][how[i][j]]=1;
answer[how[i][j]][how[i][j-1]]=1;
}
answer[how[i][m-1]][how[i][0]]=1;
answer[how[i][0]][how[i][m-1]]=1;
}
build(answer);
return 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... |