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 <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include "supertrees.h"
using namespace std;
bool ok;
int tree[10002] , n;
vector<vector<int>> a;
vector <int> x[1002];
int dfs( int idx , int lab ) {
tree[idx] = lab;
for (auto i : x[idx]) {
if (tree[i] == lab) continue;
if (tree[i] == -1) {
dfs(i,lab);
}
else {
ok = false;
}
}
return 0;
}
int construct(vector<vector<int>> p) {
n = (int)p.size();
ok = true;
memset(tree,-1,sizeof(tree));
a = p;
for (int i = 0; i < (int)a.size(); i++) {
for (int j = 0; j < (int)a.size(); j++) {
a[i][j] = 0;
if (i == j) continue;
if (p[i][j] != p[j][i] || p[i][i] != 1 ) return 0;
if (p[i][j] == 1) {
x[i].push_back(j);
}
}
}
for (int i = 0; i < n; i++) {
if (tree[i] == -1) {
dfs(i,i);
if (!ok) return 0;
}
}
for (int i = 0; i < n; i++) {
if (tree[i] == i) {
a[i] = p[i];
a[i][i] = 0;
}
else {
a[i][tree[i]] = 1;
}
}
build(a);
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... |