이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int par[1005];
int depth[1005];
vector<int> teams[1005];
int FindPre(int x) {
if (par[x] == x) {
return x;
} else {
par[x] = FindPre(par[x]);
return par[x];
}
}
bool IsSame(int x, int y) {
if (FindPre(x) == FindPre(y)) {
return true;
}
else {
return false;
}
}
void Union(int x, int y) {
int PX = FindPre(x);
int PY = FindPre(y);
if (depth[PX] > depth[PY]) {
par[PY] = PX;
}
else if (depth[PX] < depth[PY]) {
par[PX] = PY;
}
else {
par[PY] = PX;
depth[PX]++;
}
}
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n, vector<int>(n, 0));
for (int i=0; i < n; i++) {
par[i] = i;
depth[i] = 1;
}
for (int i=0; i < n-1; i++) {
for (int j=i+1; j < n; j++) {
if (p[i][j] == 1) {
Union(i,j);
}
}
}
for (int i=0; i < n; i++) {
teams[FindPre(i)].push_back(i);
}
for (int i=0; i < n-1; i++) {
for (int j=i+1; j < n; j++) {
if (p[i][j] == 0 && IsSame(i,j)) {
return 0;
}
}
}
for (int i=0; i < n; i++) {
for (int j=0; j < (int)teams[i].size()-1; j++) {
ans[teams[i][j+1]][teams[i][j]] = 1;
ans[teams[i][j]][teams[i][j+1]] = 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... |