이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "supertrees.h"
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;
struct dsu {
vector<int> p, size;
dsu(int n) : p(n), size(n, 1) {
iota(all(p), 0);
}
int get(int v) {
return v == p[v] ? v : p[v] = get(p[v]);
}
bool merge(int a, int b) {
a = get(a), b = get(b);
if (a == b) return 0;
if (size[a] < size[b]) swap(a, b);
size[a] += size[b], p[b] = a;
return 1;
}
};
int construct(std::vector<std::vector<int>> p) {
int n = sz(p);
dsu d(n);
for (int i = 0; i < n; i++) for (int j = i+1; j < n; j++) if (p[i][j]) d.merge(i, j);
for (int i = 0; i < n; i++) for (int j = i+1; j < n; j++) if (!p[i][j] && d.get(i) == d.get(j)) return 0;
vector<vector<int>> ans(n, vector<int>(n));
for (int i = 0; i < n; i++) if (i != d.get(i)) ans[i][d.get(i)] = ans[d.get(i)][i] = 1;
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... |