#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
struct uf {
vector<int> chefs;
uf (int n) {
chefs.resize(n);
for (int i = 0; i<n; i++) chefs[i] = i;
}
int find(int x) {
if (chefs[x] == x) return x;
return chefs[x] = find(chefs[x]);
}
void unite(int a, int b) {
a = find(a);
b = find(b);
chefs[a] = b;
}
};
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
if (n == 1) {
if (p[0][0] == 1) {
build({{0}});
return 1;
}
return 0;
}
vector<vector<int>> answer(n, vector<int>(n));
uf u(n);
for (int i = 0; i<n; i++) {
for (int j = 0; j<n; j++) {
if (p[i][j]) u.unite(i, j);
}
}
for (int i = 0; i<n; i++) {
for (int j = 0; j<n; j++) {
if ((bool)(p[i][j]) != (u.find(i) == u.find(j))) return 0;
}
}
vector<vector<int>> vals(n);
for (int i = 0; i<n; i++) {
for (int j = 0; j<n; j++) {
if (u.find(j) == i) vals[i].push_back(j);
}
}
for (auto v: vals) {
for (int i = 0; i<(int)(v.size()); i++) {
answer[v[i]][v[(i+1)%v.size()]] = 1;
answer[v[(i+1)%v.size()]][v[i]] = 1;
}
}
build(answer);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
b[0][0] is not 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
b[0][0] is not 0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Too many ways to get from 0 to 2, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |