#include "supertrees.h"
#include <iostream>
#include <vector>
#include <array>
#define ll int
using namespace std;
vector <ll> X[1000];
vector <ll> Z, Y, W;
vector<array<ll, 2>> V[3];
vector<vector<int>> F;
vector <int> tmp;
bool B[1000], D[1000], E[1000];
ll n, a, b, y, z, cnt, P[1000], G[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) {
a = dsu(i);
G[i] = a;
}
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;
a = dsu(u), b = dsu(v);
if (B[u]) X[u].push_back(v);
if (B[v]) X[v].push_back(u);
if (a == b) return 0;
}
for (int i=0; i<n; ++i) {
if (B[i] && X[i].size()) {
cnt = 0;
D[i] = true;
a = dsu(i), b = dsu(X[i][0]);
y = i;
if (a != b) {
P[a] = b;
++cnt;
y = X[i][0];
F[i][X[i][0]] = F[X[i][0]][i] = 1;
}
z = -1;
for (int j=0; j+1<X[i].size(); ++j) {
a = dsu(y), b = dsu(X[i][j+1]);
D[X[i][j]] = true;
if (a != b) {
F[y][X[i][j+1]] = F[X[i][j+1]][y] = 1;
++cnt;
y = z = X[i][j+1];
P[a] = b;
}
}
D[X[i].back()] = true;
if (z != -1) {
++cnt;
F[i][z] = F[z][i] = 1;
}
if (cnt == 1) return 0;
}
}
for (int i=0; i<n; ++i) {
if (!B[i] && !D[i] && E[i]) {
Z.push_back(i);
}
}
while (Z.size()) {
Y.clear();
W.clear();
if (Z.size() <= 2) return 0;
Y.push_back(Z[0]);
for (int i=1; i<Z.size(); ++i) {
if (G[Z[0]] == G[Z[i]]) Y.push_back(Z[i]);
else W.push_back(Z[i]);
}
if (Y.size() <= 2) return 0;
for (int i=0; i+1<Y.size(); ++i) {
F[Y[i]][Y[i+1]] = F[Y[i+1]][Y[i]] = 1;
}
F[Y[0]][Y.back()] = F[Y.back()][Y[0]] = 1;
swap(Z, W);
}
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:44:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | for (auto [u, v] : V[1]) {
| ^
supertrees.cpp:52:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
52 | for (auto [u, v] : V[2]) {
| ^
supertrees.cpp:72:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int j=0; j+1<X[i].size(); ++j) {
| ~~~^~~~~~~~~~~~
supertrees.cpp:100:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for (int i=1; i<Z.size(); ++i) {
| ~^~~~~~~~~
supertrees.cpp:105:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | for (int i=0; i+1<Y.size(); ++i) {
| ~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1356 KB |
Output is correct |
7 |
Correct |
171 ms |
26072 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 |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1356 KB |
Output is correct |
7 |
Correct |
171 ms |
26072 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1372 KB |
Output is correct |
13 |
Correct |
173 ms |
26056 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
980 KB |
Output is correct |
17 |
Correct |
91 ms |
16176 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
48 ms |
6904 KB |
Output is correct |
21 |
Correct |
191 ms |
26088 KB |
Output is correct |
22 |
Correct |
185 ms |
26000 KB |
Output is correct |
23 |
Correct |
188 ms |
26112 KB |
Output is correct |
24 |
Correct |
174 ms |
26008 KB |
Output is correct |
25 |
Correct |
77 ms |
16240 KB |
Output is correct |
26 |
Correct |
80 ms |
16212 KB |
Output is correct |
27 |
Correct |
185 ms |
26092 KB |
Output is correct |
28 |
Correct |
169 ms |
26064 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1356 KB |
Output is correct |
9 |
Correct |
173 ms |
26056 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1356 KB |
Output is correct |
13 |
Correct |
181 ms |
26068 KB |
Output is correct |
14 |
Correct |
0 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 |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
45 ms |
6728 KB |
Output is correct |
22 |
Correct |
187 ms |
26028 KB |
Output is correct |
23 |
Correct |
174 ms |
26188 KB |
Output is correct |
24 |
Correct |
197 ms |
26164 KB |
Output is correct |
25 |
Correct |
81 ms |
16144 KB |
Output is correct |
26 |
Correct |
76 ms |
16236 KB |
Output is correct |
27 |
Correct |
172 ms |
26060 KB |
Output is correct |
28 |
Correct |
185 ms |
26112 KB |
Output is correct |
29 |
Correct |
74 ms |
16212 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 |
212 KB |
Output is correct |
4 |
Correct |
45 ms |
6816 KB |
Output is correct |
5 |
Correct |
179 ms |
26096 KB |
Output is correct |
6 |
Correct |
174 ms |
26116 KB |
Output is correct |
7 |
Correct |
188 ms |
26116 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
53 ms |
6808 KB |
Output is correct |
10 |
Correct |
174 ms |
26088 KB |
Output is correct |
11 |
Correct |
169 ms |
26104 KB |
Output is correct |
12 |
Correct |
189 ms |
26164 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
44 ms |
6728 KB |
Output is correct |
17 |
Correct |
177 ms |
27896 KB |
Output is correct |
18 |
Correct |
176 ms |
28476 KB |
Output is correct |
19 |
Correct |
197 ms |
28112 KB |
Output is correct |
20 |
Correct |
178 ms |
28020 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 |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1356 KB |
Output is correct |
7 |
Correct |
171 ms |
26072 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1372 KB |
Output is correct |
13 |
Correct |
173 ms |
26056 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
980 KB |
Output is correct |
17 |
Correct |
91 ms |
16176 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
48 ms |
6904 KB |
Output is correct |
21 |
Correct |
191 ms |
26088 KB |
Output is correct |
22 |
Correct |
185 ms |
26000 KB |
Output is correct |
23 |
Correct |
188 ms |
26112 KB |
Output is correct |
24 |
Correct |
174 ms |
26008 KB |
Output is correct |
25 |
Correct |
77 ms |
16240 KB |
Output is correct |
26 |
Correct |
80 ms |
16212 KB |
Output is correct |
27 |
Correct |
185 ms |
26092 KB |
Output is correct |
28 |
Correct |
169 ms |
26064 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1356 KB |
Output is correct |
37 |
Correct |
173 ms |
26056 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1356 KB |
Output is correct |
41 |
Correct |
181 ms |
26068 KB |
Output is correct |
42 |
Correct |
0 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 |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
45 ms |
6728 KB |
Output is correct |
50 |
Correct |
187 ms |
26028 KB |
Output is correct |
51 |
Correct |
174 ms |
26188 KB |
Output is correct |
52 |
Correct |
197 ms |
26164 KB |
Output is correct |
53 |
Correct |
81 ms |
16144 KB |
Output is correct |
54 |
Correct |
76 ms |
16236 KB |
Output is correct |
55 |
Correct |
172 ms |
26060 KB |
Output is correct |
56 |
Correct |
185 ms |
26112 KB |
Output is correct |
57 |
Correct |
74 ms |
16212 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
980 KB |
Output is correct |
61 |
Correct |
97 ms |
16244 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
46 ms |
6720 KB |
Output is correct |
66 |
Correct |
80 ms |
18152 KB |
Output is correct |
67 |
Correct |
87 ms |
18140 KB |
Output is correct |
68 |
Correct |
87 ms |
18120 KB |
Output is correct |
69 |
Correct |
81 ms |
18112 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 |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1356 KB |
Output is correct |
7 |
Correct |
171 ms |
26072 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
8 ms |
1372 KB |
Output is correct |
13 |
Correct |
173 ms |
26056 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
5 ms |
980 KB |
Output is correct |
17 |
Correct |
91 ms |
16176 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
48 ms |
6904 KB |
Output is correct |
21 |
Correct |
191 ms |
26088 KB |
Output is correct |
22 |
Correct |
185 ms |
26000 KB |
Output is correct |
23 |
Correct |
188 ms |
26112 KB |
Output is correct |
24 |
Correct |
174 ms |
26008 KB |
Output is correct |
25 |
Correct |
77 ms |
16240 KB |
Output is correct |
26 |
Correct |
80 ms |
16212 KB |
Output is correct |
27 |
Correct |
185 ms |
26092 KB |
Output is correct |
28 |
Correct |
169 ms |
26064 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1356 KB |
Output is correct |
37 |
Correct |
173 ms |
26056 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1356 KB |
Output is correct |
41 |
Correct |
181 ms |
26068 KB |
Output is correct |
42 |
Correct |
0 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 |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
45 ms |
6728 KB |
Output is correct |
50 |
Correct |
187 ms |
26028 KB |
Output is correct |
51 |
Correct |
174 ms |
26188 KB |
Output is correct |
52 |
Correct |
197 ms |
26164 KB |
Output is correct |
53 |
Correct |
81 ms |
16144 KB |
Output is correct |
54 |
Correct |
76 ms |
16236 KB |
Output is correct |
55 |
Correct |
172 ms |
26060 KB |
Output is correct |
56 |
Correct |
185 ms |
26112 KB |
Output is correct |
57 |
Correct |
74 ms |
16212 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
45 ms |
6816 KB |
Output is correct |
62 |
Correct |
179 ms |
26096 KB |
Output is correct |
63 |
Correct |
174 ms |
26116 KB |
Output is correct |
64 |
Correct |
188 ms |
26116 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
53 ms |
6808 KB |
Output is correct |
67 |
Correct |
174 ms |
26088 KB |
Output is correct |
68 |
Correct |
169 ms |
26104 KB |
Output is correct |
69 |
Correct |
189 ms |
26164 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
44 ms |
6728 KB |
Output is correct |
74 |
Correct |
177 ms |
27896 KB |
Output is correct |
75 |
Correct |
176 ms |
28476 KB |
Output is correct |
76 |
Correct |
197 ms |
28112 KB |
Output is correct |
77 |
Correct |
178 ms |
28020 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
980 KB |
Output is correct |
81 |
Correct |
97 ms |
16244 KB |
Output is correct |
82 |
Correct |
0 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
46 ms |
6720 KB |
Output is correct |
86 |
Correct |
80 ms |
18152 KB |
Output is correct |
87 |
Correct |
87 ms |
18140 KB |
Output is correct |
88 |
Correct |
87 ms |
18120 KB |
Output is correct |
89 |
Correct |
81 ms |
18112 KB |
Output is correct |
90 |
Correct |
1 ms |
328 KB |
Output is correct |
91 |
Correct |
1 ms |
340 KB |
Output is correct |
92 |
Correct |
4 ms |
728 KB |
Output is correct |
93 |
Correct |
93 ms |
10128 KB |
Output is correct |
94 |
Correct |
1 ms |
340 KB |
Output is correct |
95 |
Correct |
1 ms |
340 KB |
Output is correct |
96 |
Correct |
1 ms |
340 KB |
Output is correct |
97 |
Correct |
16 ms |
3156 KB |
Output is correct |
98 |
Correct |
80 ms |
10872 KB |
Output is correct |
99 |
Correct |
67 ms |
11748 KB |
Output is correct |
100 |
Correct |
68 ms |
11480 KB |
Output is correct |
101 |
Correct |
73 ms |
15492 KB |
Output is correct |
102 |
Correct |
63 ms |
10144 KB |
Output is correct |
103 |
Correct |
69 ms |
10124 KB |
Output is correct |
104 |
Correct |
67 ms |
10144 KB |
Output is correct |
105 |
Correct |
73 ms |
10124 KB |
Output is correct |