#include <bits/stdc++.h>
#include "supertrees.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
struct Dsu {
vector<int> p;
void Reset(int n) {
p.resize(n);
iota(p.begin(), p.end(), 0);
}
int Find(int x) {
if (x == p[x]) return x;
return p[x] = Find(p[x]);
}
void Unite(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y) return;
p[y] = x;
}
};
int construct(vector<vector<int>> p) {
int n = p.size();
vector<vector<int>> ans(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j] == 3) return 0;
}
}
Dsu all;
all.Reset(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j] > 0) all.Unite(i, j);
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (all.Find(i) == all.Find(j) && p[i][j] == 0) return 0;
}
}
vector<vector<int>> v(n);
for (int i = 0; i < n; i++) {
v[all.Find(i)].push_back(i);
}
vector<bool> alone(n, 1);
for (int z = 0; z < n; z++) {
if (v[z].size() <= 1) continue;
vector<int> a;
int sz = v[z].size();
for (int i = 0; i < sz; i++) a.push_back(v[z][i]);
Dsu d;
d.Reset(n);
for (int i = 0; i < sz; i++) {
for (int j = i + 1; j < sz; j++) {
if (p[a[i]][a[j]] == 1) {
d.Unite(a[i], a[j]);
alone[a[i]] = alone[a[j]] = 0;
}
}
}
for (int i = 0; i < sz; i++) {
for (int j = i + 1; j < sz; j++) {
if (d.Find(a[i]) == d.Find(a[j]) && p[a[i]][a[j]] == 2) return 0;
}
}
vector<vector<int>> vv(n);
vector<int> koji;
for (int i = 0; i < sz; i++) {
vv[d.Find(a[i])].push_back(a[i]);
}
for (int i = 0; i < sz; i++) {
if (d.Find(a[i]) == a[i]) koji.push_back(a[i]);
}
int ksz = koji.size();
if (ksz == 2) return 0;
for (int i = 0; i < ksz; i++) {
int x = koji[i];
int y = koji[(i + 1) % ksz];
if (x != y) ans[x][y] = ans[y][x] = 1;
if (alone[x] == 1) continue;
int sza = vv[x].size();
for (int j = 0; j < sza - 1; j++) {
int c1 = vv[x][j];
int c2 = vv[x][j + 1];
ans[c1][c2] = ans[c2][c1] = 1;
}
}
}
build(ans);
return 1;
}
# |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1128 KB |
Output is correct |
7 |
Correct |
188 ms |
22016 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1128 KB |
Output is correct |
7 |
Correct |
188 ms |
22016 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1100 KB |
Output is correct |
13 |
Correct |
182 ms |
22028 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 |
724 KB |
Output is correct |
17 |
Correct |
80 ms |
12044 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
5732 KB |
Output is correct |
21 |
Correct |
174 ms |
22000 KB |
Output is correct |
22 |
Correct |
170 ms |
22012 KB |
Output is correct |
23 |
Correct |
191 ms |
22092 KB |
Output is correct |
24 |
Correct |
169 ms |
22016 KB |
Output is correct |
25 |
Correct |
72 ms |
12032 KB |
Output is correct |
26 |
Correct |
68 ms |
12032 KB |
Output is correct |
27 |
Correct |
187 ms |
22036 KB |
Output is correct |
28 |
Correct |
169 ms |
22220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
11 ms |
1184 KB |
Output is correct |
9 |
Correct |
194 ms |
24064 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
9 ms |
1280 KB |
Output is correct |
13 |
Correct |
181 ms |
23928 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
764 KB |
Output is correct |
17 |
Correct |
102 ms |
14080 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
300 KB |
Output is correct |
21 |
Correct |
44 ms |
6220 KB |
Output is correct |
22 |
Correct |
179 ms |
23924 KB |
Output is correct |
23 |
Correct |
170 ms |
24012 KB |
Output is correct |
24 |
Correct |
185 ms |
23936 KB |
Output is correct |
25 |
Correct |
71 ms |
14080 KB |
Output is correct |
26 |
Correct |
71 ms |
14068 KB |
Output is correct |
27 |
Correct |
175 ms |
24140 KB |
Output is correct |
28 |
Correct |
182 ms |
23920 KB |
Output is correct |
29 |
Correct |
75 ms |
14084 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 |
212 KB |
Output is correct |
4 |
Correct |
46 ms |
5780 KB |
Output is correct |
5 |
Correct |
176 ms |
21984 KB |
Output is correct |
6 |
Correct |
175 ms |
22088 KB |
Output is correct |
7 |
Correct |
191 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
45 ms |
5744 KB |
Output is correct |
10 |
Correct |
175 ms |
21964 KB |
Output is correct |
11 |
Correct |
168 ms |
22028 KB |
Output is correct |
12 |
Correct |
184 ms |
22092 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
46 ms |
5768 KB |
Output is correct |
17 |
Correct |
180 ms |
21988 KB |
Output is correct |
18 |
Correct |
197 ms |
22020 KB |
Output is correct |
19 |
Correct |
229 ms |
22056 KB |
Output is correct |
20 |
Correct |
184 ms |
22092 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1128 KB |
Output is correct |
7 |
Correct |
188 ms |
22016 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1100 KB |
Output is correct |
13 |
Correct |
182 ms |
22028 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 |
724 KB |
Output is correct |
17 |
Correct |
80 ms |
12044 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
5732 KB |
Output is correct |
21 |
Correct |
174 ms |
22000 KB |
Output is correct |
22 |
Correct |
170 ms |
22012 KB |
Output is correct |
23 |
Correct |
191 ms |
22092 KB |
Output is correct |
24 |
Correct |
169 ms |
22016 KB |
Output is correct |
25 |
Correct |
72 ms |
12032 KB |
Output is correct |
26 |
Correct |
68 ms |
12032 KB |
Output is correct |
27 |
Correct |
187 ms |
22036 KB |
Output is correct |
28 |
Correct |
169 ms |
22220 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
11 ms |
1184 KB |
Output is correct |
37 |
Correct |
194 ms |
24064 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
9 ms |
1280 KB |
Output is correct |
41 |
Correct |
181 ms |
23928 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
764 KB |
Output is correct |
45 |
Correct |
102 ms |
14080 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
300 KB |
Output is correct |
49 |
Correct |
44 ms |
6220 KB |
Output is correct |
50 |
Correct |
179 ms |
23924 KB |
Output is correct |
51 |
Correct |
170 ms |
24012 KB |
Output is correct |
52 |
Correct |
185 ms |
23936 KB |
Output is correct |
53 |
Correct |
71 ms |
14080 KB |
Output is correct |
54 |
Correct |
71 ms |
14068 KB |
Output is correct |
55 |
Correct |
175 ms |
24140 KB |
Output is correct |
56 |
Correct |
182 ms |
23920 KB |
Output is correct |
57 |
Correct |
75 ms |
14084 KB |
Output is correct |
58 |
Correct |
2 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
5 ms |
852 KB |
Output is correct |
61 |
Correct |
86 ms |
14072 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
292 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
50 ms |
6256 KB |
Output is correct |
66 |
Correct |
76 ms |
14068 KB |
Output is correct |
67 |
Correct |
77 ms |
14076 KB |
Output is correct |
68 |
Correct |
74 ms |
14068 KB |
Output is correct |
69 |
Correct |
77 ms |
14124 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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1128 KB |
Output is correct |
7 |
Correct |
188 ms |
22016 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1100 KB |
Output is correct |
13 |
Correct |
182 ms |
22028 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 |
724 KB |
Output is correct |
17 |
Correct |
80 ms |
12044 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
47 ms |
5732 KB |
Output is correct |
21 |
Correct |
174 ms |
22000 KB |
Output is correct |
22 |
Correct |
170 ms |
22012 KB |
Output is correct |
23 |
Correct |
191 ms |
22092 KB |
Output is correct |
24 |
Correct |
169 ms |
22016 KB |
Output is correct |
25 |
Correct |
72 ms |
12032 KB |
Output is correct |
26 |
Correct |
68 ms |
12032 KB |
Output is correct |
27 |
Correct |
187 ms |
22036 KB |
Output is correct |
28 |
Correct |
169 ms |
22220 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
11 ms |
1184 KB |
Output is correct |
37 |
Correct |
194 ms |
24064 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
9 ms |
1280 KB |
Output is correct |
41 |
Correct |
181 ms |
23928 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
764 KB |
Output is correct |
45 |
Correct |
102 ms |
14080 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
300 KB |
Output is correct |
49 |
Correct |
44 ms |
6220 KB |
Output is correct |
50 |
Correct |
179 ms |
23924 KB |
Output is correct |
51 |
Correct |
170 ms |
24012 KB |
Output is correct |
52 |
Correct |
185 ms |
23936 KB |
Output is correct |
53 |
Correct |
71 ms |
14080 KB |
Output is correct |
54 |
Correct |
71 ms |
14068 KB |
Output is correct |
55 |
Correct |
175 ms |
24140 KB |
Output is correct |
56 |
Correct |
182 ms |
23920 KB |
Output is correct |
57 |
Correct |
75 ms |
14084 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
46 ms |
5780 KB |
Output is correct |
62 |
Correct |
176 ms |
21984 KB |
Output is correct |
63 |
Correct |
175 ms |
22088 KB |
Output is correct |
64 |
Correct |
191 ms |
22020 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
45 ms |
5744 KB |
Output is correct |
67 |
Correct |
175 ms |
21964 KB |
Output is correct |
68 |
Correct |
168 ms |
22028 KB |
Output is correct |
69 |
Correct |
184 ms |
22092 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
46 ms |
5768 KB |
Output is correct |
74 |
Correct |
180 ms |
21988 KB |
Output is correct |
75 |
Correct |
197 ms |
22020 KB |
Output is correct |
76 |
Correct |
229 ms |
22056 KB |
Output is correct |
77 |
Correct |
184 ms |
22092 KB |
Output is correct |
78 |
Correct |
2 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
5 ms |
852 KB |
Output is correct |
81 |
Correct |
86 ms |
14072 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
292 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
50 ms |
6256 KB |
Output is correct |
86 |
Correct |
76 ms |
14068 KB |
Output is correct |
87 |
Correct |
77 ms |
14076 KB |
Output is correct |
88 |
Correct |
74 ms |
14068 KB |
Output is correct |
89 |
Correct |
77 ms |
14124 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
1 ms |
212 KB |
Output is correct |
92 |
Correct |
4 ms |
852 KB |
Output is correct |
93 |
Correct |
75 ms |
14068 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
0 ms |
212 KB |
Output is correct |
96 |
Correct |
0 ms |
212 KB |
Output is correct |
97 |
Correct |
17 ms |
3768 KB |
Output is correct |
98 |
Correct |
76 ms |
14068 KB |
Output is correct |
99 |
Correct |
76 ms |
14068 KB |
Output is correct |
100 |
Correct |
73 ms |
14064 KB |
Output is correct |
101 |
Correct |
72 ms |
14064 KB |
Output is correct |
102 |
Correct |
70 ms |
14028 KB |
Output is correct |
103 |
Correct |
71 ms |
14068 KB |
Output is correct |
104 |
Correct |
68 ms |
13988 KB |
Output is correct |
105 |
Correct |
79 ms |
13980 KB |
Output is correct |