This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7;
int nn, comp, used[N], cc[N], cmp[N], ok;
vector < int > adj[N];
void dfs( int v, int rt, vector < vector < int > > p ) {
used[v] = 1;
if ( !p[rt][v] ) {
ok = 0;
return;
}
for ( auto u: adj[v] ) {
if ( !used[u] ) {
dfs( u, rt, p );
if ( !ok ) {
return;
}
}
}
}
int construct(std::vector<std::vector<int>> p) {
nn = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < nn; i++) {
std::vector<int> row;
row.resize(nn);
answer.push_back(row);
}
for ( int i = 0; i < nn; i++ ) {
if ( !cc[i] ) {
cc[i] = ++comp;
}
cmp[ cc[i] ] = i;
for ( int j = 0; j < nn; j++ ) {
if ( p[i][j] && i != j ) {
if ( cc[j] && cc[j] != cc[i] ) {
return 0;
}
if( cc[j] ) {
continue;
}
cc[j] = cc[i];
answer[ cmp[ cc[i] ] ][j] = 1;
answer[ j ][ cmp[ cc[i] ] ] = 1;
cmp[ cc[i] ] = j;
}
}
}
for ( int i = 0; i < nn; i++ ) {
for ( int j = 0; j < nn; j++ ) {
if ( answer[i][j] ) {
adj[i].push_back(j);
}
}
}
for ( int i = 0; i < nn; i++ ) {
for ( int j = 0; j < nn; j++ ) {
used[j] = 0;
}
ok = 1;
dfs(i, i, p);
if ( !ok ) {
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... |