#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
using ll = long long;
ll n, m, q, k, x, y, a, b, c;
struct dsu {
ll n;
vector<ll> par;
vector<ll> sz;
dsu(ll N) : n(N) {
par.resize(n);
sz.resize(n);
for (int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
}
}
ll find_p(ll x) {
if (par[x] == x) {
return x;
}
ll p = find_p(par[x]);
par[x] = p;
return p;
}
void join(ll x, ll y) {
x = find_p(x);
y = find_p(y);
if (x == y) {
return;
}
if (sz[y] > sz[x]) {
swap(x, y);
}
par[y] = x;
sz[x] += sz[y];
}
};
int construct(vector< vector<int> > p) {
n = p.size();
vector< vector<int> > ans(n, vector<int>(n));
vector< vector<ll> > comp(n);
vector< vector<ll> > comp2(n);
dsu d(n);
bitset<1000> bt;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (p[i][j] == 1) {
d.join(i, j);
bt.set(i);
bt.set(j);
}
}
}
for (int i = 0; i < n; i++) {
if (!bt[i]) {
continue;
}
comp[d.find_p(i)].push_back(i);
}
for (auto i : comp) {
for (int j : i) {
for (int k : i) {
if (p[j][k] != 1) {
return 0;
}
}
}
}
for (auto i : comp) {
if (i.size() <= 1) {
continue;
}
for (int j = 0; j < i.size() - 1; j++) {
ans[i[(j + 1) % i.size()]][i[j]] = 1;
ans[i[j]][i[(j + 1) % i.size()]] = 1;
}
}
for (int i = 0; i < n; i++) {
set<ll> st2;
for (int j : comp[i]) {
for (int k = 0; k < n; k++) {
if (p[j][k] == 2) {
// if (bt[k]) {
// return 0;
// }
st2.insert(k);
}
}
}
// cout << i << ' ' << st2.size() << '\n';
for (int j : st2) {
comp2[i].push_back(j);
bt.set(j);
}
}
for (auto i : comp2) {
if (i.size() == 1) {
return 0;
}
for (int j : i) {
for (int k : i) {
if (j != k && p[j][k] != 2) {
return 0;
}
}
}
}
for (auto i = 0; i < n; i++) {
for (int j : comp[i]) {
for (int k : comp2[i]) {
if (p[j][k] != 2) {
return 0;
}
}
}
}
// cout << "DEBUG" << endl;
for (auto i = 0; i < n; i++) {
if (comp2[i].size() == 0) {
continue;
}
comp2[i].push_back(i);
for (int j = 0; j < comp2[i].size(); j++) {
ans[comp2[i][(j + 1) % comp2[i].size()]][comp2[i][j]] = 1;
ans[comp2[i][j]][comp2[i][(j + 1) % comp2[i].size()]] = 1;
}
}
vector< vector<ll> > comp2i(n);
dsu d2(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (bt[i] && !bt[j] && p[i][j] != 0) {
return 0;
}
if (!bt[i] && bt[j] && p[i][j] != 0) {
return 0;
}
if (!bt[i] && !bt[j] && p[i][j] == 2) {
d2.join(i, j);
}
}
}
for (int i = 0; i < n; i++) {
comp2i[d2.find_p(i)].push_back(i);
}
for (auto i : comp2i) {
if (i.size() == 2) {
return 0;
}
for (int j : i) {
for (int k : i) {
if (p[j][k] == 0) {
return 0;
}
}
}
}
for (auto i : comp2i) {
if (i.size() == 1) {
continue;
}
for (int j = 0; j < i.size(); j++) {
ans[i[(j + 1) % i.size()]][i[j]] = 1;
ans[i[j]][i[(j + 1) % i.size()]] = 1;
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:81:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for (int j = 0; j < i.size() - 1; j++) {
| ~~^~~~~~~~~~~~~~
supertrees.cpp:131:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | for (int j = 0; j < comp2[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:170:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
170 | for (int j = 0; j < i.size(); j++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
432 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
182 ms |
23492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
432 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
182 ms |
23492 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
223 ms |
23356 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 |
64 ms |
13396 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
30 ms |
6324 KB |
Output is correct |
21 |
Correct |
158 ms |
23376 KB |
Output is correct |
22 |
Correct |
120 ms |
23380 KB |
Output is correct |
23 |
Correct |
192 ms |
23484 KB |
Output is correct |
24 |
Correct |
153 ms |
23588 KB |
Output is correct |
25 |
Correct |
75 ms |
13488 KB |
Output is correct |
26 |
Correct |
61 ms |
13648 KB |
Output is correct |
27 |
Correct |
142 ms |
23472 KB |
Output is correct |
28 |
Correct |
120 ms |
23376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
5 ms |
1372 KB |
Output is correct |
9 |
Correct |
140 ms |
23480 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1368 KB |
Output is correct |
13 |
Correct |
154 ms |
23560 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
964 KB |
Output is correct |
17 |
Correct |
113 ms |
13636 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
604 KB |
Output is correct |
21 |
Correct |
38 ms |
6220 KB |
Output is correct |
22 |
Correct |
194 ms |
23380 KB |
Output is correct |
23 |
Correct |
180 ms |
23376 KB |
Output is correct |
24 |
Correct |
180 ms |
23376 KB |
Output is correct |
25 |
Correct |
111 ms |
13628 KB |
Output is correct |
26 |
Correct |
113 ms |
13652 KB |
Output is correct |
27 |
Correct |
132 ms |
23536 KB |
Output is correct |
28 |
Correct |
156 ms |
23380 KB |
Output is correct |
29 |
Correct |
67 ms |
13520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
32 ms |
6324 KB |
Output is correct |
5 |
Correct |
144 ms |
23380 KB |
Output is correct |
6 |
Correct |
149 ms |
23376 KB |
Output is correct |
7 |
Correct |
140 ms |
23588 KB |
Output is correct |
8 |
Correct |
0 ms |
432 KB |
Output is correct |
9 |
Correct |
30 ms |
6352 KB |
Output is correct |
10 |
Correct |
176 ms |
23376 KB |
Output is correct |
11 |
Correct |
124 ms |
23556 KB |
Output is correct |
12 |
Correct |
123 ms |
23380 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
14 ms |
3932 KB |
Answer gives possible 0 while actual possible 1 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
432 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
182 ms |
23492 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
223 ms |
23356 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 |
64 ms |
13396 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
30 ms |
6324 KB |
Output is correct |
21 |
Correct |
158 ms |
23376 KB |
Output is correct |
22 |
Correct |
120 ms |
23380 KB |
Output is correct |
23 |
Correct |
192 ms |
23484 KB |
Output is correct |
24 |
Correct |
153 ms |
23588 KB |
Output is correct |
25 |
Correct |
75 ms |
13488 KB |
Output is correct |
26 |
Correct |
61 ms |
13648 KB |
Output is correct |
27 |
Correct |
142 ms |
23472 KB |
Output is correct |
28 |
Correct |
120 ms |
23376 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
140 ms |
23480 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1368 KB |
Output is correct |
41 |
Correct |
154 ms |
23560 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
5 ms |
964 KB |
Output is correct |
45 |
Correct |
113 ms |
13636 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
604 KB |
Output is correct |
49 |
Correct |
38 ms |
6220 KB |
Output is correct |
50 |
Correct |
194 ms |
23380 KB |
Output is correct |
51 |
Correct |
180 ms |
23376 KB |
Output is correct |
52 |
Correct |
180 ms |
23376 KB |
Output is correct |
53 |
Correct |
111 ms |
13628 KB |
Output is correct |
54 |
Correct |
113 ms |
13652 KB |
Output is correct |
55 |
Correct |
132 ms |
23536 KB |
Output is correct |
56 |
Correct |
156 ms |
23380 KB |
Output is correct |
57 |
Correct |
67 ms |
13520 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
348 KB |
Output is correct |
60 |
Correct |
3 ms |
860 KB |
Output is correct |
61 |
Correct |
60 ms |
13396 KB |
Output is correct |
62 |
Correct |
0 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
388 KB |
Output is correct |
64 |
Correct |
0 ms |
360 KB |
Output is correct |
65 |
Incorrect |
28 ms |
3928 KB |
Answer gives possible 0 while actual possible 1 |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
432 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1368 KB |
Output is correct |
7 |
Correct |
182 ms |
23492 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1372 KB |
Output is correct |
13 |
Correct |
223 ms |
23356 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 |
64 ms |
13396 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
30 ms |
6324 KB |
Output is correct |
21 |
Correct |
158 ms |
23376 KB |
Output is correct |
22 |
Correct |
120 ms |
23380 KB |
Output is correct |
23 |
Correct |
192 ms |
23484 KB |
Output is correct |
24 |
Correct |
153 ms |
23588 KB |
Output is correct |
25 |
Correct |
75 ms |
13488 KB |
Output is correct |
26 |
Correct |
61 ms |
13648 KB |
Output is correct |
27 |
Correct |
142 ms |
23472 KB |
Output is correct |
28 |
Correct |
120 ms |
23376 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
5 ms |
1372 KB |
Output is correct |
37 |
Correct |
140 ms |
23480 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
5 ms |
1368 KB |
Output is correct |
41 |
Correct |
154 ms |
23560 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
5 ms |
964 KB |
Output is correct |
45 |
Correct |
113 ms |
13636 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
604 KB |
Output is correct |
49 |
Correct |
38 ms |
6220 KB |
Output is correct |
50 |
Correct |
194 ms |
23380 KB |
Output is correct |
51 |
Correct |
180 ms |
23376 KB |
Output is correct |
52 |
Correct |
180 ms |
23376 KB |
Output is correct |
53 |
Correct |
111 ms |
13628 KB |
Output is correct |
54 |
Correct |
113 ms |
13652 KB |
Output is correct |
55 |
Correct |
132 ms |
23536 KB |
Output is correct |
56 |
Correct |
156 ms |
23380 KB |
Output is correct |
57 |
Correct |
67 ms |
13520 KB |
Output is correct |
58 |
Correct |
1 ms |
344 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
32 ms |
6324 KB |
Output is correct |
62 |
Correct |
144 ms |
23380 KB |
Output is correct |
63 |
Correct |
149 ms |
23376 KB |
Output is correct |
64 |
Correct |
140 ms |
23588 KB |
Output is correct |
65 |
Correct |
0 ms |
432 KB |
Output is correct |
66 |
Correct |
30 ms |
6352 KB |
Output is correct |
67 |
Correct |
176 ms |
23376 KB |
Output is correct |
68 |
Correct |
124 ms |
23556 KB |
Output is correct |
69 |
Correct |
123 ms |
23380 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Incorrect |
14 ms |
3932 KB |
Answer gives possible 0 while actual possible 1 |
74 |
Halted |
0 ms |
0 KB |
- |