#include "supertrees.h"
#include <iostream>
#include <vector>
#include <array>
#define ll int
using namespace std;
vector <ll> X[1000];
vector <ll> Z;
vector<array<ll, 2>> V[3];
vector<vector<int>> F;
vector <int> tmp;
bool B[1000], D[1000], E[1000], R[1000][1000];
ll n, a, b, z, P[1000];
ll dsu(ll u) {
if (P[u] == u) return u;
else return P[u] = dsu(P[u]);
}
int construct(std::vector<std::vector<int>> p) {
n = p.size();
for (int i=0; i<n; ++i) P[i] = i;
for (int i=0; i<n; ++i) {
F.push_back(tmp);
for (int j=0; j<n; ++j) {
F[i].push_back(0);
if (p[i][j] == 3) return 0;
if (p[i][j]) {
a = dsu(i), b = dsu(j);
if (a != b) P[a] = b;
}
if (j > i) V[p[i][j]].push_back({i, j});
}
}
for (auto [u, v] : V[0]) {
a = dsu(u), b = dsu(v);
if (a == b) return 0;
}
for (int i=0; i<n; ++i) P[i] = i;
for (auto [u, v] : V[1]) {
a = dsu(u), b = dsu(v);
if (a != b) {
P[a] = b;
B[u] = B[v] = true;
F[u][v] = F[v][u] = 1;
}
}
for (auto [u, v] : V[2]) {
E[u] = E[v] = 1;
if (B[u]) X[u].push_back(v);
else if (B[v]) X[v].push_back(u);
a = dsu(u), b = dsu(v);
if (a == b) return 0;
}
for (int i=0; i<n; ++i) {
if (B[i] && X[i].size() == 1) return 0;
}
for (int i=0; i<n; ++i) {
if (B[i] && X[i].size()) {
a = dsu(i);
if (R[a][X[i][0]]) continue;
R[a][X[i][0]] = true;
if (D[X[i][0]]) {
F[i][X[i][0]] = F[X[i][0]][i] = 1;
for (int j=0; j<X[i].size(); ++j) {
if (!D[X[i][j]]) return 0;
}
continue;
}
F[i][X[i][0]] = F[X[i][0]][i] = 1;
for (int j=0; j+1<X[i].size(); ++j) {
D[X[i][j]] = true;
F[X[i][j]][X[i][j+1]] = F[X[i][j+1]][X[i][j]] = 1;
}
D[X[i].back()] = true;
F[i][X[i].back()] = F[X[i].back()][i] = 1;
}
}
for (int i=0; i<n; ++i) {
if (!B[i] && !D[i] && E[i]) {
Z.push_back(i);
}
}
if (Z.size()) {
if (Z.size() <= 2) return 0;
for (int i=0; i+1<Z.size(); ++i) {
F[Z[i]][Z[i+1]] = F[Z[i+1]][Z[i]] = 1;
}
F[Z[0]][Z.back()] = F[Z.back()][Z[0]] = 1;
}
build(F);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:35:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
35 | for (auto [u, v] : V[0]) {
| ^
supertrees.cpp:40:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
40 | for (auto [u, v] : V[1]) {
| ^
supertrees.cpp:48:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
48 | for (auto [u, v] : V[2]) {
| ^
supertrees.cpp:65:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int j=0; j<X[i].size(); ++j) {
| ~^~~~~~~~~~~~
supertrees.cpp:71:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int j=0; j+1<X[i].size(); ++j) {
| ~~~^~~~~~~~~~~~
supertrees.cpp:86:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for (int i=0; i+1<Z.size(); ++i) {
| ~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
8 ms |
1484 KB |
Output is correct |
7 |
Correct |
186 ms |
28096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
8 ms |
1484 KB |
Output is correct |
7 |
Correct |
186 ms |
28096 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
10 ms |
1456 KB |
Output is correct |
13 |
Correct |
181 ms |
28016 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1108 KB |
Output is correct |
17 |
Correct |
91 ms |
18056 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
46 ms |
7292 KB |
Output is correct |
21 |
Correct |
183 ms |
28008 KB |
Output is correct |
22 |
Correct |
186 ms |
27984 KB |
Output is correct |
23 |
Correct |
204 ms |
28036 KB |
Output is correct |
24 |
Correct |
179 ms |
27976 KB |
Output is correct |
25 |
Correct |
79 ms |
18148 KB |
Output is correct |
26 |
Correct |
75 ms |
18148 KB |
Output is correct |
27 |
Correct |
195 ms |
28024 KB |
Output is correct |
28 |
Correct |
176 ms |
28040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
9 ms |
1380 KB |
Output is correct |
9 |
Correct |
185 ms |
26116 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1356 KB |
Output is correct |
13 |
Correct |
183 ms |
26136 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
980 KB |
Output is correct |
17 |
Correct |
89 ms |
16144 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Incorrect |
50 ms |
6780 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
47 ms |
7280 KB |
Output is correct |
5 |
Correct |
194 ms |
28044 KB |
Output is correct |
6 |
Correct |
180 ms |
27964 KB |
Output is correct |
7 |
Correct |
193 ms |
28032 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Incorrect |
58 ms |
7248 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
8 ms |
1484 KB |
Output is correct |
7 |
Correct |
186 ms |
28096 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
10 ms |
1456 KB |
Output is correct |
13 |
Correct |
181 ms |
28016 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1108 KB |
Output is correct |
17 |
Correct |
91 ms |
18056 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
46 ms |
7292 KB |
Output is correct |
21 |
Correct |
183 ms |
28008 KB |
Output is correct |
22 |
Correct |
186 ms |
27984 KB |
Output is correct |
23 |
Correct |
204 ms |
28036 KB |
Output is correct |
24 |
Correct |
179 ms |
27976 KB |
Output is correct |
25 |
Correct |
79 ms |
18148 KB |
Output is correct |
26 |
Correct |
75 ms |
18148 KB |
Output is correct |
27 |
Correct |
195 ms |
28024 KB |
Output is correct |
28 |
Correct |
176 ms |
28040 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
9 ms |
1380 KB |
Output is correct |
37 |
Correct |
185 ms |
26116 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
8 ms |
1356 KB |
Output is correct |
41 |
Correct |
183 ms |
26136 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
980 KB |
Output is correct |
45 |
Correct |
89 ms |
16144 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Incorrect |
50 ms |
6780 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
50 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
8 ms |
1484 KB |
Output is correct |
7 |
Correct |
186 ms |
28096 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
10 ms |
1456 KB |
Output is correct |
13 |
Correct |
181 ms |
28016 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
1108 KB |
Output is correct |
17 |
Correct |
91 ms |
18056 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
46 ms |
7292 KB |
Output is correct |
21 |
Correct |
183 ms |
28008 KB |
Output is correct |
22 |
Correct |
186 ms |
27984 KB |
Output is correct |
23 |
Correct |
204 ms |
28036 KB |
Output is correct |
24 |
Correct |
179 ms |
27976 KB |
Output is correct |
25 |
Correct |
79 ms |
18148 KB |
Output is correct |
26 |
Correct |
75 ms |
18148 KB |
Output is correct |
27 |
Correct |
195 ms |
28024 KB |
Output is correct |
28 |
Correct |
176 ms |
28040 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
9 ms |
1380 KB |
Output is correct |
37 |
Correct |
185 ms |
26116 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
8 ms |
1356 KB |
Output is correct |
41 |
Correct |
183 ms |
26136 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
980 KB |
Output is correct |
45 |
Correct |
89 ms |
16144 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Incorrect |
50 ms |
6780 KB |
Too many ways to get from 0 to 1, should be 0 found no less than 1 |
50 |
Halted |
0 ms |
0 KB |
- |