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 <vector>
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3+3;
const int inf = 1e9;
int par[N], ran[N];
int find_p(int a) {
return (a == par[a]) ? a : find_p(par[a]);
}
void unitee(int a, int b) {
a = find_p(a), b = find_p(b);
if(a == b) return;
if(ran[a] < ran[b]) swap(a, b);
par[b] = par[a];
if(ran[a]==ran[b]) ran[a]++;
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> answer;
for (int i = 0; i < n; i++) {
std::vector<int> row;
row.resize(n);
answer.push_back(row);
}
for(int i = 0; i < n; i++) par[i] = i, ran[i] = 1;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j]==1) {
unitee(i, j);
}
}
}
map<int, set<int>> M;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(i==j) {
answer[i][j] = 0;
continue;
}
if(p[i][j] == 0 && find_p(i)==find_p(j)) return 0;
answer[i][j] = 0;
if(p[i][j]==1) {
int pp = find_p(i);
if(pp != i)answer[pp][i] = 1, answer[i][pp] = 1;
if(pp != j)answer[pp][j] = 1, answer[j][pp] = 1;
}
}
}
answer[0][0] = 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... |