이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "supertrees.h"
using namespace std;
int n;
vector<int> father;
int root(int node){
if(father[node] == node) return node;
return father[node] = root(father[node]);
}
int merge(int NodeA, int NodeB, vector<vector<int>> p){
int rootA = root(NodeA);
int rootB = root(NodeB);
if(rootB == rootA) return 1;
father[rootA] = rootB;
for(int i = 0; i < n; ++i){
if(i == rootA or i == rootB)continue;
if(!(((p[rootA][i]) and (p[rootB][i])) or ((!p[rootA][i]) and (!p[rootB][i])))) return 0;
}
return 1;
}
int construct(vector<vector<int>> p){
n = p[0].size();
father = vector<int>(n);
for(int i = 0; i < n; ++i) {
father[i] = i;
}
for(int i = 0; i < n; ++i){
for(int j = i+1; j < n; ++j){
if(p[i][j]){
int sol = merge(i, j, p);
if(!sol) return 0;
}else{
for(int k = 0; k < n; ++k){
if(k == i or k==j) continue;
if(p[i][k] and p[j][k]) return 0;
}
}
}
}
vector<vector<int>> edges(n, vector<int>(n, 0));
for(int i = 0; i < n; ++i) {
int MyRoot = root(i);
if(MyRoot==i) continue;
edges[MyRoot][i] = edges[i][MyRoot] = 1;
}
build(edges);
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... |