#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[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] != 0 && seen.count(groups[y]) == 0) {
adj[g].push_back(groups[y]);
seen.insert(groups[y]);
adj[groups[y]].push_back(g);
}
}
}
// 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;
vector<int> gs = adj[i];
gs.insert(gs.begin(), i);
vector<int> twos, threes, ones;
if (gs.size() == 1) continue;
// cout << i << "\n";
// for (int y : gs) cout << y << " ";
// cout << "\n";
for (int x : gs)
{
vector<int> test = adj[x];
test.insert(lower_bound(test.begin(), test.end(), x), x);
// for (int y : test) cout << y << " ";
// cout << "\n";
if (test != gs) goto impossible;
done[x] = true;
int one = 0;
bool two, three;
two = three = false;
for (int y : p[gnode[x]])
{
if (y == 1) one ++;
else if (y == 2) two = true;
else if (y == 3) three = true;
}
if (two && three) goto impossible;
if (one > 1) ones.emplace_back(x);
else if (two) twos.emplace_back(x);
else if (three) threes.emplace_back(x);
}
// cout << "Counting finished\n";
// cerr << ones.size() << " " << twos.size() << " " << threes.size() << " \n";
if (threes.empty())
{
// Twos
if (gs.size() < 3) goto impossible;
// 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 (twos.empty())
{
if (gs.size() < 4) goto impossible;
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;
output[gnode[gs[0]]][gnode[gs[2]]] = output[gnode[gs[2]]][gnode[gs[0]]] = 1;
}
}
// Build
build(output);
return 1;
impossible:
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
183 ms |
22044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
183 ms |
22044 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
170 ms |
22044 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
72 ms |
12064 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
41 ms |
5792 KB |
Output is correct |
21 |
Correct |
170 ms |
22008 KB |
Output is correct |
22 |
Correct |
164 ms |
22048 KB |
Output is correct |
23 |
Correct |
185 ms |
21968 KB |
Output is correct |
24 |
Correct |
172 ms |
22044 KB |
Output is correct |
25 |
Correct |
69 ms |
12076 KB |
Output is correct |
26 |
Correct |
70 ms |
12060 KB |
Output is correct |
27 |
Correct |
172 ms |
22080 KB |
Output is correct |
28 |
Correct |
166 ms |
22028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1156 KB |
Output is correct |
9 |
Correct |
166 ms |
22044 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
9 ms |
1432 KB |
Output is correct |
13 |
Correct |
211 ms |
26140 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
852 KB |
Output is correct |
17 |
Correct |
118 ms |
14892 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
49 ms |
5808 KB |
Output is correct |
22 |
Correct |
169 ms |
22548 KB |
Output is correct |
23 |
Correct |
166 ms |
22044 KB |
Output is correct |
24 |
Correct |
199 ms |
25372 KB |
Output is correct |
25 |
Correct |
68 ms |
12076 KB |
Output is correct |
26 |
Correct |
75 ms |
12620 KB |
Output is correct |
27 |
Correct |
179 ms |
22040 KB |
Output is correct |
28 |
Correct |
194 ms |
24120 KB |
Output is correct |
29 |
Correct |
68 ms |
12072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
43 ms |
5788 KB |
Output is correct |
5 |
Correct |
171 ms |
22044 KB |
Output is correct |
6 |
Correct |
170 ms |
22020 KB |
Output is correct |
7 |
Correct |
168 ms |
22040 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
47 ms |
5812 KB |
Output is correct |
10 |
Correct |
173 ms |
22644 KB |
Output is correct |
11 |
Correct |
166 ms |
22052 KB |
Output is correct |
12 |
Correct |
195 ms |
25352 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Incorrect |
23 ms |
3276 KB |
Answer gives possible 0 while actual possible 1 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
183 ms |
22044 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
170 ms |
22044 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
72 ms |
12064 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
41 ms |
5792 KB |
Output is correct |
21 |
Correct |
170 ms |
22008 KB |
Output is correct |
22 |
Correct |
164 ms |
22048 KB |
Output is correct |
23 |
Correct |
185 ms |
21968 KB |
Output is correct |
24 |
Correct |
172 ms |
22044 KB |
Output is correct |
25 |
Correct |
69 ms |
12076 KB |
Output is correct |
26 |
Correct |
70 ms |
12060 KB |
Output is correct |
27 |
Correct |
172 ms |
22080 KB |
Output is correct |
28 |
Correct |
166 ms |
22028 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1156 KB |
Output is correct |
37 |
Correct |
166 ms |
22044 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
9 ms |
1432 KB |
Output is correct |
41 |
Correct |
211 ms |
26140 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
118 ms |
14892 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
49 ms |
5808 KB |
Output is correct |
50 |
Correct |
169 ms |
22548 KB |
Output is correct |
51 |
Correct |
166 ms |
22044 KB |
Output is correct |
52 |
Correct |
199 ms |
25372 KB |
Output is correct |
53 |
Correct |
68 ms |
12076 KB |
Output is correct |
54 |
Correct |
75 ms |
12620 KB |
Output is correct |
55 |
Correct |
179 ms |
22040 KB |
Output is correct |
56 |
Correct |
194 ms |
24120 KB |
Output is correct |
57 |
Correct |
68 ms |
12072 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
724 KB |
Output is correct |
61 |
Correct |
71 ms |
12068 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
0 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Incorrect |
47 ms |
5756 KB |
Too many ways to get from 46 to 129, should be 2 found no less than 3 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
183 ms |
22044 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
170 ms |
22044 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
72 ms |
12064 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
41 ms |
5792 KB |
Output is correct |
21 |
Correct |
170 ms |
22008 KB |
Output is correct |
22 |
Correct |
164 ms |
22048 KB |
Output is correct |
23 |
Correct |
185 ms |
21968 KB |
Output is correct |
24 |
Correct |
172 ms |
22044 KB |
Output is correct |
25 |
Correct |
69 ms |
12076 KB |
Output is correct |
26 |
Correct |
70 ms |
12060 KB |
Output is correct |
27 |
Correct |
172 ms |
22080 KB |
Output is correct |
28 |
Correct |
166 ms |
22028 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1156 KB |
Output is correct |
37 |
Correct |
166 ms |
22044 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
9 ms |
1432 KB |
Output is correct |
41 |
Correct |
211 ms |
26140 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
4 ms |
852 KB |
Output is correct |
45 |
Correct |
118 ms |
14892 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
49 ms |
5808 KB |
Output is correct |
50 |
Correct |
169 ms |
22548 KB |
Output is correct |
51 |
Correct |
166 ms |
22044 KB |
Output is correct |
52 |
Correct |
199 ms |
25372 KB |
Output is correct |
53 |
Correct |
68 ms |
12076 KB |
Output is correct |
54 |
Correct |
75 ms |
12620 KB |
Output is correct |
55 |
Correct |
179 ms |
22040 KB |
Output is correct |
56 |
Correct |
194 ms |
24120 KB |
Output is correct |
57 |
Correct |
68 ms |
12072 KB |
Output is correct |
58 |
Correct |
1 ms |
256 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
43 ms |
5788 KB |
Output is correct |
62 |
Correct |
171 ms |
22044 KB |
Output is correct |
63 |
Correct |
170 ms |
22020 KB |
Output is correct |
64 |
Correct |
168 ms |
22040 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
47 ms |
5812 KB |
Output is correct |
67 |
Correct |
173 ms |
22644 KB |
Output is correct |
68 |
Correct |
166 ms |
22052 KB |
Output is correct |
69 |
Correct |
195 ms |
25352 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Incorrect |
23 ms |
3276 KB |
Answer gives possible 0 while actual possible 1 |
74 |
Halted |
0 ms |
0 KB |
- |