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 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] == 2) {
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;
}
if ((int)teams[i].size() > 1) {
ans[teams[i][0]][teams[i][(int)teams[i].size()-1]] = 1;
ans[teams[i][(int)teams[i].size()-1]][teams[i][0]] = 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... |