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 <vector>
#include <numeric>
using namespace std;
const int MAXN = 1e3;
int pa[MAXN];
int ra[MAXN];
void init() {
iota(pa, pa + MAXN, 0);
fill(ra, ra + MAXN, 0);
}
int get(int a) {
if (a == pa[a])
return a;
return pa[a] = get(pa[a]);
}
void merge(int a, int b) {
a = get(a);
b = get(b);
if (a == b)
return;
if (ra[b] > ra[a])
swap(a, b);
pa[b] = a;
if (ra[a] == ra[b])
ra[a]++;
}
int construct(vector<vector<int>> p) {
init();
int n = p.size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
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 (p[i][j] == 1) {
if (get(i) != get(j)) {
merge(i, j);
answer[i][j] = 1;
answer[j][i] = 1;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j] == 0) {
if (get(i) == get(j)) {
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... |