#include "supertrees.h"
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using arr = array<int, 2>;
using arrr = array<int, 3>;
constexpr int maxn = 1e3 + 5;
int next_group = 1;
int groups[maxn] = { 0 }, gnode[maxn] = { 0 }, siz[maxn] = { 0 };
bool done[maxn] = { 0 };
vector <int> adj[2][maxn];
int construct(std::vector<std::vector<int>> p) {
int g;
int n = p.size();
vector<vector<int>> output(n, vector<int>(n));
for (int i = 0; i < n; i++)
{
if (groups[i]) continue;
g = next_group++;
vector<int> clique = { i };
for (int y = i + 1; y < n; y++)
{
if (p[i][y] == 1) clique.emplace_back(y);
}
gnode[g] = i;
for (int y : clique) {
groups[y] = g;
if (p[y] != p[gnode[g]]) goto impossible;
}
for (int i = 1; i < (int)clique.size(); i++)
{
output[clique[i]][clique[i - 1]] = output[clique[i - 1]][clique[i]] = 1;
}
siz[g] = clique.size();
set <int> seen;
for (int y = 0; y < i; y++)
{
if (p[i][y] == 2 && seen.count(groups[y]) == 0) {
adj[0][g].push_back(groups[y]);
adj[0][groups[y]].push_back(g);
}
if (p[i][y] == 3 && seen.count(groups[y]) == 0) {
adj[1][g].push_back(groups[y]);
adj[1][groups[y]].push_back(g);
}
seen.insert(groups[y]);
}
}
// cerr << "Groups complete\n";
// Combining groups
// in each connected component, there must be either 2, 3, or none, but not both
for (int i = 1; i < next_group; i++)
{
if (done[i]) continue;
if (!adj[0][i].empty() && !adj[1][i].empty()) goto impossible;
int t;
if (!adj[0][i].empty()) t = 0;
else t = 1;
vector<int> gs = adj[t][i];
gs.insert(gs.begin(), i);
if (gs.size() == 1) continue;
if (gs.size() == 2) goto impossible;
for (int x : gs)
{
if (!adj[t ^ 1][x].empty()) goto impossible;
vector<int> test = adj[t][x];
test.insert(lower_bound(test.begin(), test.end(), x), x);
if (test != gs) goto impossible;
assert(!done[x]);
done[x] = true;
}
// Make a cycle
for (int y = 0; y < (int)gs.size() - 1; y++) {
output[gnode[gs[y]]][gnode[gs[y + 1]]] = output[gnode[gs[y + 1]]][gnode[gs[y]]] = 1;
}
output[gnode[gs[0]]][gnode[gs[gs.size() - 1]]] = output[gnode[gs[gs.size() - 1]]][gnode[gs[0]]] = 1;
if (t == 0)
{
if (gs.size() < 3) goto impossible;
}
else
{
if (gs.size() < 4) goto impossible;
output[gnode[gs[0]]][gnode[gs[2]]] = output[gnode[gs[2]]][gnode[gs[0]]] = 1;
}
}
// Build
build(output);
return 1;
impossible:
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
6 ms |
1236 KB |
Output is correct |
7 |
Correct |
147 ms |
22672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
6 ms |
1236 KB |
Output is correct |
7 |
Correct |
147 ms |
22672 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
352 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
172 ms |
22520 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
62 ms |
12652 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
37 ms |
5928 KB |
Output is correct |
21 |
Correct |
148 ms |
22604 KB |
Output is correct |
22 |
Correct |
149 ms |
22628 KB |
Output is correct |
23 |
Correct |
168 ms |
22568 KB |
Output is correct |
24 |
Correct |
174 ms |
22584 KB |
Output is correct |
25 |
Correct |
62 ms |
12656 KB |
Output is correct |
26 |
Correct |
57 ms |
12700 KB |
Output is correct |
27 |
Correct |
156 ms |
22564 KB |
Output is correct |
28 |
Correct |
168 ms |
22552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
0 ms |
352 KB |
Output is correct |
8 |
Correct |
7 ms |
1236 KB |
Output is correct |
9 |
Correct |
175 ms |
22496 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1492 KB |
Output is correct |
13 |
Correct |
193 ms |
26644 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
352 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
104 ms |
15080 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
43 ms |
6000 KB |
Output is correct |
22 |
Correct |
175 ms |
22872 KB |
Output is correct |
23 |
Correct |
171 ms |
22444 KB |
Output is correct |
24 |
Correct |
189 ms |
25584 KB |
Output is correct |
25 |
Correct |
87 ms |
12380 KB |
Output is correct |
26 |
Correct |
87 ms |
12972 KB |
Output is correct |
27 |
Correct |
174 ms |
22368 KB |
Output is correct |
28 |
Correct |
189 ms |
24372 KB |
Output is correct |
29 |
Correct |
86 ms |
12456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
356 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
37 ms |
5904 KB |
Output is correct |
5 |
Correct |
148 ms |
22624 KB |
Output is correct |
6 |
Correct |
160 ms |
22748 KB |
Output is correct |
7 |
Correct |
153 ms |
22552 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
43 ms |
5924 KB |
Output is correct |
10 |
Correct |
179 ms |
23100 KB |
Output is correct |
11 |
Correct |
175 ms |
22604 KB |
Output is correct |
12 |
Correct |
193 ms |
25872 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
42 ms |
5988 KB |
Output is correct |
17 |
Correct |
174 ms |
23196 KB |
Output is correct |
18 |
Correct |
159 ms |
22884 KB |
Output is correct |
19 |
Correct |
159 ms |
22708 KB |
Output is correct |
20 |
Correct |
179 ms |
22584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
6 ms |
1236 KB |
Output is correct |
7 |
Correct |
147 ms |
22672 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
352 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
172 ms |
22520 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
62 ms |
12652 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
37 ms |
5928 KB |
Output is correct |
21 |
Correct |
148 ms |
22604 KB |
Output is correct |
22 |
Correct |
149 ms |
22628 KB |
Output is correct |
23 |
Correct |
168 ms |
22568 KB |
Output is correct |
24 |
Correct |
174 ms |
22584 KB |
Output is correct |
25 |
Correct |
62 ms |
12656 KB |
Output is correct |
26 |
Correct |
57 ms |
12700 KB |
Output is correct |
27 |
Correct |
156 ms |
22564 KB |
Output is correct |
28 |
Correct |
168 ms |
22552 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
592 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
356 KB |
Output is correct |
35 |
Correct |
0 ms |
352 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
175 ms |
22496 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1492 KB |
Output is correct |
41 |
Correct |
193 ms |
26644 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
352 KB |
Output is correct |
44 |
Correct |
4 ms |
980 KB |
Output is correct |
45 |
Correct |
104 ms |
15080 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
43 ms |
6000 KB |
Output is correct |
50 |
Correct |
175 ms |
22872 KB |
Output is correct |
51 |
Correct |
171 ms |
22444 KB |
Output is correct |
52 |
Correct |
189 ms |
25584 KB |
Output is correct |
53 |
Correct |
87 ms |
12380 KB |
Output is correct |
54 |
Correct |
87 ms |
12972 KB |
Output is correct |
55 |
Correct |
174 ms |
22368 KB |
Output is correct |
56 |
Correct |
189 ms |
24372 KB |
Output is correct |
57 |
Correct |
86 ms |
12456 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
3 ms |
852 KB |
Output is correct |
61 |
Correct |
61 ms |
12344 KB |
Output is correct |
62 |
Correct |
0 ms |
356 KB |
Output is correct |
63 |
Correct |
0 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
43 ms |
6104 KB |
Output is correct |
66 |
Correct |
61 ms |
12660 KB |
Output is correct |
67 |
Correct |
61 ms |
12560 KB |
Output is correct |
68 |
Correct |
59 ms |
12536 KB |
Output is correct |
69 |
Correct |
83 ms |
12568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
6 ms |
1236 KB |
Output is correct |
7 |
Correct |
147 ms |
22672 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
352 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
172 ms |
22520 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
62 ms |
12652 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
37 ms |
5928 KB |
Output is correct |
21 |
Correct |
148 ms |
22604 KB |
Output is correct |
22 |
Correct |
149 ms |
22628 KB |
Output is correct |
23 |
Correct |
168 ms |
22568 KB |
Output is correct |
24 |
Correct |
174 ms |
22584 KB |
Output is correct |
25 |
Correct |
62 ms |
12656 KB |
Output is correct |
26 |
Correct |
57 ms |
12700 KB |
Output is correct |
27 |
Correct |
156 ms |
22564 KB |
Output is correct |
28 |
Correct |
168 ms |
22552 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
592 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
356 KB |
Output is correct |
35 |
Correct |
0 ms |
352 KB |
Output is correct |
36 |
Correct |
7 ms |
1236 KB |
Output is correct |
37 |
Correct |
175 ms |
22496 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
7 ms |
1492 KB |
Output is correct |
41 |
Correct |
193 ms |
26644 KB |
Output is correct |
42 |
Correct |
0 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
352 KB |
Output is correct |
44 |
Correct |
4 ms |
980 KB |
Output is correct |
45 |
Correct |
104 ms |
15080 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
43 ms |
6000 KB |
Output is correct |
50 |
Correct |
175 ms |
22872 KB |
Output is correct |
51 |
Correct |
171 ms |
22444 KB |
Output is correct |
52 |
Correct |
189 ms |
25584 KB |
Output is correct |
53 |
Correct |
87 ms |
12380 KB |
Output is correct |
54 |
Correct |
87 ms |
12972 KB |
Output is correct |
55 |
Correct |
174 ms |
22368 KB |
Output is correct |
56 |
Correct |
189 ms |
24372 KB |
Output is correct |
57 |
Correct |
86 ms |
12456 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
356 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
37 ms |
5904 KB |
Output is correct |
62 |
Correct |
148 ms |
22624 KB |
Output is correct |
63 |
Correct |
160 ms |
22748 KB |
Output is correct |
64 |
Correct |
153 ms |
22552 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
43 ms |
5924 KB |
Output is correct |
67 |
Correct |
179 ms |
23100 KB |
Output is correct |
68 |
Correct |
175 ms |
22604 KB |
Output is correct |
69 |
Correct |
193 ms |
25872 KB |
Output is correct |
70 |
Correct |
1 ms |
340 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
42 ms |
5988 KB |
Output is correct |
74 |
Correct |
174 ms |
23196 KB |
Output is correct |
75 |
Correct |
159 ms |
22884 KB |
Output is correct |
76 |
Correct |
159 ms |
22708 KB |
Output is correct |
77 |
Correct |
179 ms |
22584 KB |
Output is correct |
78 |
Correct |
1 ms |
340 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
3 ms |
852 KB |
Output is correct |
81 |
Correct |
61 ms |
12344 KB |
Output is correct |
82 |
Correct |
0 ms |
356 KB |
Output is correct |
83 |
Correct |
0 ms |
340 KB |
Output is correct |
84 |
Correct |
1 ms |
348 KB |
Output is correct |
85 |
Correct |
43 ms |
6104 KB |
Output is correct |
86 |
Correct |
61 ms |
12660 KB |
Output is correct |
87 |
Correct |
61 ms |
12560 KB |
Output is correct |
88 |
Correct |
59 ms |
12536 KB |
Output is correct |
89 |
Correct |
83 ms |
12568 KB |
Output is correct |
90 |
Correct |
1 ms |
340 KB |
Output is correct |
91 |
Correct |
1 ms |
340 KB |
Output is correct |
92 |
Correct |
3 ms |
852 KB |
Output is correct |
93 |
Correct |
62 ms |
12556 KB |
Output is correct |
94 |
Correct |
1 ms |
340 KB |
Output is correct |
95 |
Correct |
1 ms |
340 KB |
Output is correct |
96 |
Correct |
0 ms |
340 KB |
Output is correct |
97 |
Correct |
20 ms |
3500 KB |
Output is correct |
98 |
Correct |
89 ms |
13100 KB |
Output is correct |
99 |
Correct |
66 ms |
12560 KB |
Output is correct |
100 |
Correct |
63 ms |
12688 KB |
Output is correct |
101 |
Correct |
82 ms |
12588 KB |
Output is correct |
102 |
Incorrect |
196 ms |
26420 KB |
Answer gives possible 1 while actual possible 0 |
103 |
Halted |
0 ms |
0 KB |
- |