#include <bits/stdc++.h>
using namespace std;
#include "supertrees.h"
#include <vector>
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> ans (n, vector < int > (n));
vector < array < bool, 3 > > pt (n);
vector < pair < int, int > > dsu (n);
set < int > r;
for (int i = 0; i < n; ++i) dsu[i].first = -1, dsu[i].second = 1;
auto dsuc = [&] (int x)
{
while (dsu[x].first != -1) x = dsu[x].first;
return x;
};
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
if (p[i][j])
{
if (p[i][j] == 3) return 0;
pt[i][p[i][j]] = pt[j][p[i][j]] = true;
if (p[i][j] == 1 && !r.count (i) && !r.count (j))
ans[i][j] = 1, ans[j][i] = 1, r.insert (j);
int ci = dsuc (i), cj = dsuc (j);
if (ci != cj)
{
if (dsu[ci].second < dsu[cj].second) swap (ci, cj);
dsu[cj].first = ci;
dsu[ci].second += dsu[cj].second;
}
}
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
if (!p[i][j] && dsuc (i) == dsuc (j)) return 0;
map < int, array < set < int >, 3 > > m;
for (int i = 0; i < n; ++i)
{
int ci = dsuc (i);
if (pt[i][1]) m[ci][1].insert (i);
if (pt[i][2]) m[ci][2].insert (i);
}
for (auto &[xx, x] : m)
{
if (x[1].empty () && x[2].empty ()) continue;
if (x[2].empty ())
{
int pr = -1;
for (auto &y : x[1])
{
if (x[2].size () && !x[2].count (y)) return 0;
if (pr >= 0) ans[pr][y] = ans[y][pr] = 1;
pr = y;
}
}
if (x[2].size () <= 2) return 0;
int pr = *prev (x[2].end ());
for (auto &y : x[2])
{
if (r.count (y)) continue;
ans[pr][y] = ans[y][pr] = 1;
pr = y;
for (int i = 0; i < n; ++i)
if (i != y && x[1].count (i) && p[y][i] == 1)
ans[i][y] = ans[y][i] = 1;
}
}
build (ans);
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 |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
7 ms |
1372 KB |
Output is correct |
9 |
Correct |
149 ms |
23480 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
8 ms |
1340 KB |
Output is correct |
13 |
Correct |
155 ms |
23484 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
74 ms |
13460 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
39 ms |
6236 KB |
Output is correct |
22 |
Correct |
155 ms |
23588 KB |
Output is correct |
23 |
Correct |
154 ms |
23436 KB |
Output is correct |
24 |
Correct |
163 ms |
23380 KB |
Output is correct |
25 |
Correct |
63 ms |
13224 KB |
Output is correct |
26 |
Correct |
70 ms |
13224 KB |
Output is correct |
27 |
Correct |
154 ms |
23252 KB |
Output is correct |
28 |
Correct |
162 ms |
23224 KB |
Output is correct |
29 |
Correct |
66 ms |
13396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 0 while actual possible 1 |
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 |
- |