이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
bool used[maxn];
vector < int > v[maxn],c;
void dfs( int x )
{
if( used[x] )return;
used[x] = true;
c.push_back(x);
for( auto y : v[x] ){
dfs( y );
}
}
int construct( vector<vector<int>> p )
{
int n = (int)p.size();
for( int i = 0; i < n; i++ ){
if( p[i][i] != 1 )return 0;
for( int j = 0; j < n; j++ ){
if( p[i][j] == 3 || p[i][j] != p[j][i] )return 0;
if( p[i][j] == 0 )continue;
if( p[i][j] == 1 ){
v[i].push_back(j);
}
}
}
vector < vector < int > > ans( n , vector < int > (n , 0) );
vector < int > fg;
for( int it = 0; it < n; it++ ){
if( used[it] )continue;
c.clear();
dfs( it );
fg.push_back(it);
int sz = (int)c.size();
int cnt1 = 0 , cnt2 = 0;
vector < int > ch( n , 0 );
for( int i = 0; i < sz; i++ ){
ch[c[i]] = 1;
for( int j = 0; j < sz; j++ ){
int x = c[i] , y = c[j];
if( p[x][y] != 1 ){
return 0;
}
}
if( i + 1 < sz ){
int x = c[i] , y = c[i + 1];
ans[x][y] = ans[y][x] = 1;
}
}
for( int i = 0; i < sz; i++ ){
for( int j = 0; j < n; j++ ){
int x = c[i] , y = j;
if( ch[y] )continue;
cnt1 += 1;
if( p[x][y] == 0 )cnt2 += 1;
}
}
if( cnt2 == cnt1 ){
fg.pop_back();
}else if( cnt2 > 0 )return 0;
}
for( int i = 0; i < n; i++ ){
used[i] = false;
v[i].clear();
for( int j = 0; j < n; j++ ){
if( p[i][j] != 0 ){
v[i].push_back(j);
}
}
}
for( int i = 0; i < n; i++ ){
if( used[i] )continue;
c.clear();
dfs( i );
int sz = (int)c.size();
for( int j = 0; j < sz; j++ ){
for( int h = 0; h < sz; h++ ){
int x = c[j] , y = c[h];
if( p[x][y] == 0 ){
return 0;
}
}
}
}
if( !fg.empty() && (int)fg.size() < 3 )return 0;
for( int i = 0; i + 1 < (int)fg.size(); i++ ){
int x = fg[i] , y = fg[i + 1];
ans[x][y] = ans[y][x] = 1;
}
if( !fg.empty() ){
int x = fg[0] , y = fg.back();
ans[x][y] = ans[y][x] = 1;
}
build( ans );
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... |