#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);
vector< vector<ll> > comp2a(n);
dsu d(n);
bitset<1000> bt;
for (int i = 0; i < n; i++) {
if (p[i][i] != 1) {
return 0;
}
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 (int i = 0; i < n; i++) {
if (!bt[i]) {
continue;
}
for (int j : comp[i]) {
for (int k : comp[i]) {
if (p[j][k] != 1) {
return 0;
}
}
}
}
for (int i = 0; i < n; i++) {
if (!bt[i]) {
continue;
}
if (comp[i].size() <= 1) {
continue;
}
for (int j = 0; j < comp[i].size() - 1; j++) {
ans[comp[i][j + 1]][comp[i][j]] = 1;
ans[comp[i][j]][comp[i][j + 1]] = 1;
}
}
bitset<1000> bt2;
bitset<1000> bt2_;
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 (p[i][j] == 2) {
d2.join(i, j);
bt2_.set(i);
bt2_.set(j);
}
}
}
for (int i = 0; i < n; i++) {
if (!bt2_[i]) {
continue;
}
ll x = i;
if (bt[i]) {
x = d.find_p(i);
}
if (bt2[x]) {
continue;
}
bt2.set(x);
comp2[d2.find_p(x)].push_back(x);
}
for (int i = 0; i < n; i++) {
if (!bt2[i]) {
continue;
}
if (comp2[i].size() == 2) {
return 0;
}
for (int j = 0; j < comp2[i].size(); j++) {
// cout << comp2[i][j] << '\n';
ans[comp2[i][(j + 1) % comp2[i].size()]][comp2[i][j]] = 1;
ans[comp2[i][j]][comp2[i][(j + 1) % comp2[i].size()]] = 1;
}
// cout << '\n';
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:91:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for (int j = 0; j < comp[i].size() - 1; j++) {
| ~~^~~~~~~~~~~~~~~~~~~~
supertrees.cpp:135:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for (int j = 0; j < comp2[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1192 KB |
Output is correct |
7 |
Correct |
123 ms |
24016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1192 KB |
Output is correct |
7 |
Correct |
123 ms |
24016 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
440 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
122 ms |
24048 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
67 ms |
14144 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
36 ms |
6228 KB |
Output is correct |
21 |
Correct |
124 ms |
24184 KB |
Output is correct |
22 |
Correct |
125 ms |
24148 KB |
Output is correct |
23 |
Correct |
126 ms |
24148 KB |
Output is correct |
24 |
Correct |
118 ms |
24144 KB |
Output is correct |
25 |
Correct |
57 ms |
14256 KB |
Output is correct |
26 |
Correct |
53 ms |
14212 KB |
Output is correct |
27 |
Correct |
129 ms |
24144 KB |
Output is correct |
28 |
Correct |
123 ms |
24148 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
1384 KB |
Output is correct |
9 |
Correct |
120 ms |
23892 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
132 ms |
24148 KB |
Output is correct |
14 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
15 |
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 |
31 ms |
6220 KB |
Output is correct |
5 |
Correct |
126 ms |
24144 KB |
Output is correct |
6 |
Correct |
119 ms |
24148 KB |
Output is correct |
7 |
Correct |
136 ms |
24148 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
31 ms |
6372 KB |
Output is correct |
10 |
Correct |
120 ms |
24072 KB |
Output is correct |
11 |
Correct |
132 ms |
24144 KB |
Output is correct |
12 |
Correct |
132 ms |
24252 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
31 ms |
6296 KB |
Too few ways to get from 0 to 24, should be 2 found 0 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1192 KB |
Output is correct |
7 |
Correct |
123 ms |
24016 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
440 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
122 ms |
24048 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
67 ms |
14144 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
36 ms |
6228 KB |
Output is correct |
21 |
Correct |
124 ms |
24184 KB |
Output is correct |
22 |
Correct |
125 ms |
24148 KB |
Output is correct |
23 |
Correct |
126 ms |
24148 KB |
Output is correct |
24 |
Correct |
118 ms |
24144 KB |
Output is correct |
25 |
Correct |
57 ms |
14256 KB |
Output is correct |
26 |
Correct |
53 ms |
14212 KB |
Output is correct |
27 |
Correct |
129 ms |
24144 KB |
Output is correct |
28 |
Correct |
123 ms |
24148 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1384 KB |
Output is correct |
37 |
Correct |
120 ms |
23892 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
6 ms |
1372 KB |
Output is correct |
41 |
Correct |
132 ms |
24148 KB |
Output is correct |
42 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1192 KB |
Output is correct |
7 |
Correct |
123 ms |
24016 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
440 KB |
Output is correct |
12 |
Correct |
6 ms |
1372 KB |
Output is correct |
13 |
Correct |
122 ms |
24048 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
67 ms |
14144 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
36 ms |
6228 KB |
Output is correct |
21 |
Correct |
124 ms |
24184 KB |
Output is correct |
22 |
Correct |
125 ms |
24148 KB |
Output is correct |
23 |
Correct |
126 ms |
24148 KB |
Output is correct |
24 |
Correct |
118 ms |
24144 KB |
Output is correct |
25 |
Correct |
57 ms |
14256 KB |
Output is correct |
26 |
Correct |
53 ms |
14212 KB |
Output is correct |
27 |
Correct |
129 ms |
24144 KB |
Output is correct |
28 |
Correct |
123 ms |
24148 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1384 KB |
Output is correct |
37 |
Correct |
120 ms |
23892 KB |
Output is correct |
38 |
Correct |
0 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
6 ms |
1372 KB |
Output is correct |
41 |
Correct |
132 ms |
24148 KB |
Output is correct |
42 |
Incorrect |
0 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
43 |
Halted |
0 ms |
0 KB |
- |