#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;
}
// cout << x << endl;
bt2.set(x);
// cout << '\t' << d2.find_p(x) << '\n';
comp2[d2.find_p(x)].push_back(x);
}
// cout << comp2[3].size() << '\n';
for (int i = 0; i < n; i++) {
if (comp2[i].size() <= 1) {
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';
}
dsu du(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (ans[i][j]) {
du.join(i, j);
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (du.find_p(i) == du.find_p(j) && p[i][j] == 0) {
return 0;
}
}
}
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:138:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
138 | for (int j = 0; j < comp2[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
1216 KB |
Output is correct |
7 |
Correct |
134 ms |
24240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
1216 KB |
Output is correct |
7 |
Correct |
134 ms |
24240 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1368 KB |
Output is correct |
13 |
Correct |
126 ms |
24072 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
68 ms |
14212 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
62 ms |
6264 KB |
Output is correct |
21 |
Correct |
123 ms |
24200 KB |
Output is correct |
22 |
Correct |
153 ms |
24144 KB |
Output is correct |
23 |
Correct |
169 ms |
24068 KB |
Output is correct |
24 |
Correct |
130 ms |
24148 KB |
Output is correct |
25 |
Correct |
55 ms |
14164 KB |
Output is correct |
26 |
Correct |
64 ms |
14164 KB |
Output is correct |
27 |
Correct |
129 ms |
24056 KB |
Output is correct |
28 |
Correct |
156 ms |
24184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
440 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
1372 KB |
Output is correct |
9 |
Correct |
125 ms |
23916 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1368 KB |
Output is correct |
13 |
Correct |
131 ms |
24400 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 |
63 ms |
14212 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
33 ms |
6228 KB |
Output is correct |
22 |
Correct |
130 ms |
24160 KB |
Output is correct |
23 |
Correct |
126 ms |
24072 KB |
Output is correct |
24 |
Correct |
133 ms |
24056 KB |
Output is correct |
25 |
Correct |
54 ms |
14084 KB |
Output is correct |
26 |
Correct |
52 ms |
14164 KB |
Output is correct |
27 |
Correct |
124 ms |
24148 KB |
Output is correct |
28 |
Correct |
130 ms |
24052 KB |
Output is correct |
29 |
Correct |
59 ms |
14164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
39 ms |
6384 KB |
Output is correct |
5 |
Correct |
126 ms |
24148 KB |
Output is correct |
6 |
Correct |
123 ms |
24144 KB |
Output is correct |
7 |
Correct |
144 ms |
24144 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
32 ms |
6232 KB |
Output is correct |
10 |
Correct |
122 ms |
24064 KB |
Output is correct |
11 |
Correct |
115 ms |
24148 KB |
Output is correct |
12 |
Correct |
128 ms |
24184 KB |
Output is correct |
13 |
Correct |
0 ms |
436 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
42 ms |
6260 KB |
Output is correct |
17 |
Correct |
130 ms |
24148 KB |
Output is correct |
18 |
Correct |
123 ms |
24148 KB |
Output is correct |
19 |
Correct |
135 ms |
24196 KB |
Output is correct |
20 |
Correct |
134 ms |
24148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
1216 KB |
Output is correct |
7 |
Correct |
134 ms |
24240 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1368 KB |
Output is correct |
13 |
Correct |
126 ms |
24072 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
68 ms |
14212 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
62 ms |
6264 KB |
Output is correct |
21 |
Correct |
123 ms |
24200 KB |
Output is correct |
22 |
Correct |
153 ms |
24144 KB |
Output is correct |
23 |
Correct |
169 ms |
24068 KB |
Output is correct |
24 |
Correct |
130 ms |
24148 KB |
Output is correct |
25 |
Correct |
55 ms |
14164 KB |
Output is correct |
26 |
Correct |
64 ms |
14164 KB |
Output is correct |
27 |
Correct |
129 ms |
24056 KB |
Output is correct |
28 |
Correct |
156 ms |
24184 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
440 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1372 KB |
Output is correct |
37 |
Correct |
125 ms |
23916 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
6 ms |
1368 KB |
Output is correct |
41 |
Correct |
131 ms |
24400 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
63 ms |
14212 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
33 ms |
6228 KB |
Output is correct |
50 |
Correct |
130 ms |
24160 KB |
Output is correct |
51 |
Correct |
126 ms |
24072 KB |
Output is correct |
52 |
Correct |
133 ms |
24056 KB |
Output is correct |
53 |
Correct |
54 ms |
14084 KB |
Output is correct |
54 |
Correct |
52 ms |
14164 KB |
Output is correct |
55 |
Correct |
124 ms |
24148 KB |
Output is correct |
56 |
Correct |
130 ms |
24052 KB |
Output is correct |
57 |
Correct |
59 ms |
14164 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 |
1112 KB |
Output is correct |
61 |
Correct |
69 ms |
14308 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
348 KB |
Output is correct |
65 |
Correct |
30 ms |
6228 KB |
Output is correct |
66 |
Correct |
89 ms |
14164 KB |
Output is correct |
67 |
Correct |
55 ms |
14088 KB |
Output is correct |
68 |
Correct |
57 ms |
14204 KB |
Output is correct |
69 |
Correct |
54 ms |
14212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
6 |
Correct |
6 ms |
1216 KB |
Output is correct |
7 |
Correct |
134 ms |
24240 KB |
Output is correct |
8 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
12 |
Correct |
6 ms |
1368 KB |
Output is correct |
13 |
Correct |
126 ms |
24072 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
68 ms |
14212 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
62 ms |
6264 KB |
Output is correct |
21 |
Correct |
123 ms |
24200 KB |
Output is correct |
22 |
Correct |
153 ms |
24144 KB |
Output is correct |
23 |
Correct |
169 ms |
24068 KB |
Output is correct |
24 |
Correct |
130 ms |
24148 KB |
Output is correct |
25 |
Correct |
55 ms |
14164 KB |
Output is correct |
26 |
Correct |
64 ms |
14164 KB |
Output is correct |
27 |
Correct |
129 ms |
24056 KB |
Output is correct |
28 |
Correct |
156 ms |
24184 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
440 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
6 ms |
1372 KB |
Output is correct |
37 |
Correct |
125 ms |
23916 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
6 ms |
1368 KB |
Output is correct |
41 |
Correct |
131 ms |
24400 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
3 ms |
860 KB |
Output is correct |
45 |
Correct |
63 ms |
14212 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
33 ms |
6228 KB |
Output is correct |
50 |
Correct |
130 ms |
24160 KB |
Output is correct |
51 |
Correct |
126 ms |
24072 KB |
Output is correct |
52 |
Correct |
133 ms |
24056 KB |
Output is correct |
53 |
Correct |
54 ms |
14084 KB |
Output is correct |
54 |
Correct |
52 ms |
14164 KB |
Output is correct |
55 |
Correct |
124 ms |
24148 KB |
Output is correct |
56 |
Correct |
130 ms |
24052 KB |
Output is correct |
57 |
Correct |
59 ms |
14164 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
39 ms |
6384 KB |
Output is correct |
62 |
Correct |
126 ms |
24148 KB |
Output is correct |
63 |
Correct |
123 ms |
24144 KB |
Output is correct |
64 |
Correct |
144 ms |
24144 KB |
Output is correct |
65 |
Correct |
1 ms |
344 KB |
Output is correct |
66 |
Correct |
32 ms |
6232 KB |
Output is correct |
67 |
Correct |
122 ms |
24064 KB |
Output is correct |
68 |
Correct |
115 ms |
24148 KB |
Output is correct |
69 |
Correct |
128 ms |
24184 KB |
Output is correct |
70 |
Correct |
0 ms |
436 KB |
Output is correct |
71 |
Correct |
0 ms |
348 KB |
Output is correct |
72 |
Correct |
1 ms |
348 KB |
Output is correct |
73 |
Correct |
42 ms |
6260 KB |
Output is correct |
74 |
Correct |
130 ms |
24148 KB |
Output is correct |
75 |
Correct |
123 ms |
24148 KB |
Output is correct |
76 |
Correct |
135 ms |
24196 KB |
Output is correct |
77 |
Correct |
134 ms |
24148 KB |
Output is correct |
78 |
Correct |
0 ms |
348 KB |
Output is correct |
79 |
Correct |
0 ms |
348 KB |
Output is correct |
80 |
Correct |
3 ms |
1112 KB |
Output is correct |
81 |
Correct |
69 ms |
14308 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
1 ms |
348 KB |
Output is correct |
84 |
Correct |
1 ms |
348 KB |
Output is correct |
85 |
Correct |
30 ms |
6228 KB |
Output is correct |
86 |
Correct |
89 ms |
14164 KB |
Output is correct |
87 |
Correct |
55 ms |
14088 KB |
Output is correct |
88 |
Correct |
57 ms |
14204 KB |
Output is correct |
89 |
Correct |
54 ms |
14212 KB |
Output is correct |
90 |
Correct |
0 ms |
348 KB |
Output is correct |
91 |
Correct |
1 ms |
348 KB |
Output is correct |
92 |
Correct |
3 ms |
928 KB |
Output is correct |
93 |
Correct |
57 ms |
14164 KB |
Output is correct |
94 |
Incorrect |
1 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
95 |
Halted |
0 ms |
0 KB |
- |