#include "supertrees.h"
#include <vector>
#include <map>
#include <iostream>
using namespace std;
struct DSU {
int n;
vector<int> link, size;
DSU(int sz) {
n = sz;
link.resize(sz);
size.resize(sz);
for (int i = 0; i < n; i++) {
link[i] = i;
size[i] = 1;
}
}
int find(int x) {
while (x != link[x])
x = link[x];
return x;
}
bool same(int a, int b) {
return find(a) == find(b);
}
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return;
if (size[a] < size[b])
swap(a, b);
link[b] = a;
size[a] += size[b];
}
};
int construct(std::vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> answer(n, vector<int>(n));
vector<vector<int>> c(n);
DSU d(n+1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j)
continue;
if (p[i][j]) {
if (!d.same(i, j)) {
d.unite(i, j);
int x = d.find(i);
c[x].push_back(j);
c[x].push_back(i);
}
}
}
}
// for (int i = 0; i < n; i++) {
// cout << i << ": ";
// for (auto x : c[i])
// cout << x << ' ';
// cout << '\n';
// }
for (int i = 0; i < n; i++) {
if (c[i].empty())
continue;
if (c[i].size() == 2)
return 0;
for (int j = 0; j < (int)c[i].size(); j++) {
for (int k = j+1; k < (int)c[i].size(); k++) {
if (!p[c[i][j]][c[i][k]])
return 0;
}
}
for (int j = 0; j < (int)c[i].size()-1; j++) {
answer[c[i][j]][c[i][j+1]] = 1;
answer[c[i][j+1]][c[i][j]] = 1;
}
answer[c[i][0]][c[i].back()] = 1;
answer[c[i].back()][c[i][0]] = 1;
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
432 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Too few ways to get from 0 to 1, should be 2 found 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |