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;
vector<int> dsu, sz;
int find (int u) {
return u == dsu[u] ? u : dsu[u] = find(dsu[u]);
}
bool unite (int u, int v) {
if ((u = find(u)) != (v = find(v))) {
if (sz[u] < sz[v]) {
swap(u, v);
}
dsu[v] = u;
sz[u] += sz[v];
return 1;
}
return 0;
}
int construct(vector<vector<int>> p) {
int n = p.size();
dsu.resize(n);
iota(dsu.begin(), dsu.end(), 0);
sz.resize(n, 1);
vector<vector<int>> ans(n, vector<int>(n));
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (p[i][j] == 1) {
ans[i][j] = ans[j][i] = unite(i, j);
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (p[i][j] == 0 && find(i) == find(j)) {
return 0;
}
}
}
build(ans);
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... |