#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;
vector<bool> done(n);
vector<int> x;
for (int j = 0; j < (int)c[i].size(); j++) {
x.push_back(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)x.size()-1; j++) {
answer[x[j]][x[j+1]] = 1;
answer[x[j+1]][x[j]] = 1;
}
answer[x[0]][x.back()] = 1;
answer[x.back()][x[0]] = 1;
}
build(answer);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
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 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 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 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |