이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1005;
int par[mxN], siz[mxN];
/*
void build(vector<vector<int> > b) {
int n = int(b.size());
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++)
cout << b[i][j] << " ";
cout << "\n";
}
}
*/
void make_set(int x) {
par[x] = x, siz[x] = 1;
}
int find_set(int x) {
return x == par[x] ? x : par[x] = find_set(par[x]);
}
void union_sets(int a, int b) {
a = find_set(a), b = find_set(b);
if(a == b) return;
if(siz[a] < siz[b])
swap(a, b);
par[b] = a, siz[a] += siz[b];
}
int construct(vector<vector<int> > p) {
int n = int(p.size());
for(int i = 0; i < n; i++)
make_set(i);
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j] == 1) {
union_sets(i, j);
// cout << i << " " << j << "\n";
}
}
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
if(p[i][j] == 0 && find_set(i) == find_set(j))
return 0;
}
}
vector<vector<int> > b(n, vector<int>(n, 0));
for(int i = 0; i < n; i++) {
int parent = find_set(i);
if(parent == i) continue;
b[i][parent] = b[parent][i] = 1;
}
build(b);
return 1;
}
/*
int main() {
int n;
scanf("%d", &n);
vector<vector<int> > p(n, vector<int>(n));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++)
scanf("%d", &p[i][j]);
}
cout << "\n";
printf("%d\n", construct(p));
return 0;
}
*/
# | 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... |