#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++) {
if (!done[c[i][j]])
x.push_back(c[i][j]);
done[c[i][j]] = true;
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 |
348 KB |
Output is correct |
2 |
Incorrect |
1 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 |
1 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 |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
432 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
118 ms |
24060 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
136 ms |
24060 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
65 ms |
14204 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
28 ms |
6284 KB |
Output is correct |
22 |
Correct |
114 ms |
23984 KB |
Output is correct |
23 |
Correct |
111 ms |
24144 KB |
Output is correct |
24 |
Correct |
119 ms |
24148 KB |
Output is correct |
25 |
Correct |
50 ms |
14212 KB |
Output is correct |
26 |
Correct |
49 ms |
14160 KB |
Output is correct |
27 |
Correct |
111 ms |
24148 KB |
Output is correct |
28 |
Correct |
118 ms |
24144 KB |
Output is correct |
29 |
Correct |
52 ms |
14092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
440 KB |
Too many ways to get from 1 to 3, should be 1 found no less than 2 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 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 |
1 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
3 |
Halted |
0 ms |
0 KB |
- |