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;
const int NAX = 1002;
vector<int> parent(NAX, -1);
int Find(int u){
if (parent[u] == -1) return u;
return parent[u] = Find(parent[u]);
}
int construct(vector<vector<int> > p) {
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);
}
// solve:
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
if (i==j) continue;
if (p[i][j] == 1){
int x = Find(i), y = Find(j);
if (x!=y){
parent[x]=y;
answer[i][j]=answer[j][i]=1;
}
}
}
}
for (int i=0; i<n; i++){
for (int j=0; j<n; j++){
if (i==j) continue;
int x = Find(i), y = Find(j);
if (p[i][j] == 1){
if (x!=y) return 0;
}else{
if (x==y) 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... |