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;
int link[1005], sz[1005];
vector<int> vec[1005];
int find(int x) {
if (x == link[x]) return x;
return link[x] = find(link[x]);
}
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b) return;
if (sz[b] > sz[a]) swap(a, b);
sz[a] += sz[b];
for (int i : vec[b]) vec[a].push_back(i);
link[b] = a;
}
int construct(vector<vector<int> > p) {
int n = p.size();
for (int i = 0; i < n; i++) {
link[i] = i;
sz[i] = 1;
vec[i].push_back(i);
}
vector<vector<int> > b(n, vector<int>(n));
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (p[i][j]) unite(i, j);
for (int i = 0; i < n; i++) {
if (find(i) != i) continue;
int prv = -1;
for (int j : vec[i]) {
if (prv != -1) b[prv][j] = b[j][prv] = 1;
prv = j;
}
if (vec[i][0] != vec[i].back()) {
b[vec[i][0]][vec[i].back()] = 1;
b[vec[i].back()][vec[i][0]] = 1;
}
}
bool inv = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (find(i) == find(j) && !p[i][j]) inv = 1;
else if (find(i) != find(j) && p[i][j]) inv = 1;
if (inv) return 0;
build(b);
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... |