이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
vector < int > adj[N], visited(N);
bool first[N];
void dfs( int v ) {
visited[v] = 1;
for ( auto u: adj[v] ) {
if ( !visited[u] ) {
dfs(u);
}
}
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
for ( int i = 0; i < n; i++ ) {
for ( int j = 0; j < n; j++ ) {
if ( i == j ) {
continue;
}
if ( p[i][j] == 1 ) {
adj[i].push_back(j);
}
}
}
vector < int > comp, used(n + 7);
for ( int i = 0; i < n; i++ ) {
if ( visited[i] ) {
continue;
}
for ( auto j: adj[i] ) {
visited[j] = 1;
}
comp.push_back(i);
}
int cnt = 0;
for ( int i = 0; i < n; i++ ) {
if ( used[i] ) {
continue;
}
used[i] = 1;
for ( auto j: adj[i] ) {
answer[i][j] = 1;
used[j] = 1;
answer[j][i] = 1;
for ( auto k: adj[i] ) {
if ( j != k && p[j][k] != 1 ) {
return 0;
}
}
}
}
int sz = comp.size();
used = vector < int > (n + 7);
for ( int i = 0; i < sz; i++ ) {
vector < int > vc = { comp[i] }, us(n + 7);
if ( used[ comp[i] ] ) {
continue;
}
used[ comp[i] ] = i + 1;
us[ comp[i] ] = 1;
for ( int j = 0; j < sz; j++ ) {
if ( i != j && p[ comp[i] ][ comp[j] ] == 2 ) {
vc.push_back(comp[j]);
us[comp[j]] = 1;
used[ comp[j] ] = i + 1;
}
}
for ( auto v: vc ) {
for ( int j = 0; j < sz; j++ ) {
int u = comp[j];
if ( v != u && p[ v ][u] == 0 ) {
for ( auto x: adj[v] ) {
for ( auto y: adj[u] ) {
if ( p[x][y] ) {
return 0;
}
}
}
}
if ( v != u && p[v][u] == 2 && !us[u] ) {
return 0;
}
}
}
int szz = vc.size();
if ( szz == 2 ) {
return 0;
}
for ( int i = 0; i < szz; i++ ) {
cnt += adj[ vc[i] ].size() + 1;
for ( int j = 0; j < szz; j++ ) {
if ( i == j ) {
continue;
}
if ( p[ vc[i] ][ vc[j] ] != 2 ) {
return 0;
}
int v = vc[i], u = vc[j];
for ( auto x: adj[v] ) {
for ( auto y: adj[u] ) {
if( p[x][y] != 2 ) {
return 0;
}
}
}
}
}
for ( int i = 0; i < szz - 1; i++ ) {
answer[vc[i]][vc[i + 1]] = 1;
answer[ vc[i + 1] ][ vc[i] ] = 1;
}
if ( szz > 1 ) {
answer[ vc[szz - 1] ][ vc[0] ] = 1;
answer[ vc[ 0 ] ][ vc[szz - 1] ] = 1;
}
}
if ( cnt != n ) {
return 0;
}
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... |