#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
#define pb push_back
#define sz size()
const int N = 1005;
int a[N][N], a1, par[N], par1[N];
vector <int> q;
vector<vector<int>> answer;
int get (int x) {
if (x == par[x]) return x;
return par[x] = get (par[x]);
}
void uni (int x, int y) {
x = get (x);
y = get (y);
par[max (x, y)] = min(x, y);
}
int get1 (int x) {
if (x == par1[x]) return x;
return par1[x] = get1 (par1[x]);
}
void uni1 (int x, int y) {
x = get1 (x);
y = get1 (y);
par1[max (x, y)] = min (x, y);
}
int construct(vector<vector<int>> p) {
int n = p.size();
for (int i = 0; i < n; ++i) {
par[i] = i;
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
assert (p[i][j] == p[j][i]);
if (i == j) continue;
if (p[i][j] == 3) return 0;
if (p[i][j]) {
uni (i, j);
}
a1 = max (a1, p[i][j]);
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j) continue;
if (!p[i][j] and get(i) == get(j)) return 0;
}
}
for (int i = 0; i < n; ++i) {
q.clear();
for (int j = 0; j < n; ++j) {
if (get(j) == i) q.pb (j);
}
if ((int)q.sz == 0) continue;
for (int i = 0; i < n; ++i) par1[i] = i;
for (int ii = 0; ii < (int)q.sz; ++ii) {
for (int jj = 0; jj < (int)q.sz; ++jj) {
if (ii == jj) continue;
if (p[q[ii]][q[jj]] == 1) {
uni1(ii, jj);
}
}
}
vector <vector <int>> g((int)q.sz);
for (int j = 0; j < (int)q.sz; ++j) {
g[get1(j)].pb (q[j]);
}
vector <int> h;
for (int j = 0; j < (int)g.sz; ++j) {
if ((int)g[j].sz) {
h.pb (g[j][0]);
}
for (int k = 0; k + 1< (int)g[j].sz; ++k) {
a[g[j][k]][g[j][k + 1]] = 1;
a[g[j][k + 1]][g[j][k]] = 1;
}
}
if ((int)h.sz == 2 and a1 == 2) return 0;
if ((int)h.sz > 2 and a1 == 2) {
if (!h.empty()) h.pb (h[0]);
for (int j = 0; j < (int)h.sz - 1; ++j) {
a[h[j]][h[j + 1]] = 1;
a[h[j + 1]][h[j]] = 1;
}
}
}
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
for (int j = 0; j < n; ++j) {
if (a[i][j]) row[j] = 1;
}
answer.push_back(row);
}
build(answer);
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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
1996 KB |
Output is correct |
7 |
Correct |
157 ms |
26000 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
1996 KB |
Output is correct |
7 |
Correct |
157 ms |
26000 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1156 KB |
Output is correct |
13 |
Correct |
150 ms |
22060 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
67 ms |
8088 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
7544 KB |
Output is correct |
21 |
Correct |
158 ms |
25932 KB |
Output is correct |
22 |
Correct |
158 ms |
25488 KB |
Output is correct |
23 |
Correct |
169 ms |
25944 KB |
Output is correct |
24 |
Correct |
155 ms |
22284 KB |
Output is correct |
25 |
Correct |
64 ms |
8076 KB |
Output is correct |
26 |
Correct |
58 ms |
8200 KB |
Output is correct |
27 |
Correct |
158 ms |
26000 KB |
Output is correct |
28 |
Correct |
155 ms |
22284 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 |
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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
7 ms |
1108 KB |
Output is correct |
9 |
Correct |
151 ms |
21992 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
7 ms |
1876 KB |
Output is correct |
13 |
Correct |
152 ms |
26000 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
66 ms |
8092 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 |
212 KB |
Output is correct |
21 |
Correct |
39 ms |
7508 KB |
Output is correct |
22 |
Correct |
155 ms |
25932 KB |
Output is correct |
23 |
Correct |
171 ms |
25952 KB |
Output is correct |
24 |
Correct |
160 ms |
25980 KB |
Output is correct |
25 |
Correct |
64 ms |
8344 KB |
Output is correct |
26 |
Correct |
60 ms |
8076 KB |
Output is correct |
27 |
Correct |
162 ms |
25932 KB |
Output is correct |
28 |
Correct |
169 ms |
25908 KB |
Output is correct |
29 |
Correct |
64 ms |
8396 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 |
44 ms |
7616 KB |
Output is correct |
5 |
Correct |
159 ms |
25880 KB |
Output is correct |
6 |
Correct |
156 ms |
25548 KB |
Output is correct |
7 |
Correct |
173 ms |
26016 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
43 ms |
7500 KB |
Output is correct |
10 |
Correct |
157 ms |
26004 KB |
Output is correct |
11 |
Correct |
189 ms |
25880 KB |
Output is correct |
12 |
Correct |
161 ms |
26004 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
40 ms |
7600 KB |
Output is correct |
17 |
Correct |
159 ms |
25920 KB |
Output is correct |
18 |
Correct |
165 ms |
25792 KB |
Output is correct |
19 |
Correct |
183 ms |
25936 KB |
Output is correct |
20 |
Correct |
152 ms |
22204 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
1996 KB |
Output is correct |
7 |
Correct |
157 ms |
26000 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1156 KB |
Output is correct |
13 |
Correct |
150 ms |
22060 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
67 ms |
8088 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
7544 KB |
Output is correct |
21 |
Correct |
158 ms |
25932 KB |
Output is correct |
22 |
Correct |
158 ms |
25488 KB |
Output is correct |
23 |
Correct |
169 ms |
25944 KB |
Output is correct |
24 |
Correct |
155 ms |
22284 KB |
Output is correct |
25 |
Correct |
64 ms |
8076 KB |
Output is correct |
26 |
Correct |
58 ms |
8200 KB |
Output is correct |
27 |
Correct |
158 ms |
26000 KB |
Output is correct |
28 |
Correct |
155 ms |
22284 KB |
Output is correct |
29 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1108 KB |
Output is correct |
37 |
Correct |
151 ms |
21992 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
7 ms |
1876 KB |
Output is correct |
41 |
Correct |
152 ms |
26000 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
596 KB |
Output is correct |
45 |
Correct |
66 ms |
8092 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 |
212 KB |
Output is correct |
49 |
Correct |
39 ms |
7508 KB |
Output is correct |
50 |
Correct |
155 ms |
25932 KB |
Output is correct |
51 |
Correct |
171 ms |
25952 KB |
Output is correct |
52 |
Correct |
160 ms |
25980 KB |
Output is correct |
53 |
Correct |
64 ms |
8344 KB |
Output is correct |
54 |
Correct |
60 ms |
8076 KB |
Output is correct |
55 |
Correct |
162 ms |
25932 KB |
Output is correct |
56 |
Correct |
169 ms |
25908 KB |
Output is correct |
57 |
Correct |
64 ms |
8396 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
3 ms |
596 KB |
Output is correct |
61 |
Correct |
68 ms |
8080 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
0 ms |
340 KB |
Output is correct |
64 |
Correct |
0 ms |
340 KB |
Output is correct |
65 |
Correct |
44 ms |
7596 KB |
Output is correct |
66 |
Correct |
59 ms |
8092 KB |
Output is correct |
67 |
Correct |
59 ms |
8092 KB |
Output is correct |
68 |
Correct |
94 ms |
8084 KB |
Output is correct |
69 |
Correct |
63 ms |
8216 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
1996 KB |
Output is correct |
7 |
Correct |
157 ms |
26000 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1156 KB |
Output is correct |
13 |
Correct |
150 ms |
22060 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
67 ms |
8088 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
41 ms |
7544 KB |
Output is correct |
21 |
Correct |
158 ms |
25932 KB |
Output is correct |
22 |
Correct |
158 ms |
25488 KB |
Output is correct |
23 |
Correct |
169 ms |
25944 KB |
Output is correct |
24 |
Correct |
155 ms |
22284 KB |
Output is correct |
25 |
Correct |
64 ms |
8076 KB |
Output is correct |
26 |
Correct |
58 ms |
8200 KB |
Output is correct |
27 |
Correct |
158 ms |
26000 KB |
Output is correct |
28 |
Correct |
155 ms |
22284 KB |
Output is correct |
29 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
7 ms |
1108 KB |
Output is correct |
37 |
Correct |
151 ms |
21992 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
7 ms |
1876 KB |
Output is correct |
41 |
Correct |
152 ms |
26000 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
596 KB |
Output is correct |
45 |
Correct |
66 ms |
8092 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 |
212 KB |
Output is correct |
49 |
Correct |
39 ms |
7508 KB |
Output is correct |
50 |
Correct |
155 ms |
25932 KB |
Output is correct |
51 |
Correct |
171 ms |
25952 KB |
Output is correct |
52 |
Correct |
160 ms |
25980 KB |
Output is correct |
53 |
Correct |
64 ms |
8344 KB |
Output is correct |
54 |
Correct |
60 ms |
8076 KB |
Output is correct |
55 |
Correct |
162 ms |
25932 KB |
Output is correct |
56 |
Correct |
169 ms |
25908 KB |
Output is correct |
57 |
Correct |
64 ms |
8396 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 |
44 ms |
7616 KB |
Output is correct |
62 |
Correct |
159 ms |
25880 KB |
Output is correct |
63 |
Correct |
156 ms |
25548 KB |
Output is correct |
64 |
Correct |
173 ms |
26016 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
43 ms |
7500 KB |
Output is correct |
67 |
Correct |
157 ms |
26004 KB |
Output is correct |
68 |
Correct |
189 ms |
25880 KB |
Output is correct |
69 |
Correct |
161 ms |
26004 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Correct |
0 ms |
340 KB |
Output is correct |
73 |
Correct |
40 ms |
7600 KB |
Output is correct |
74 |
Correct |
159 ms |
25920 KB |
Output is correct |
75 |
Correct |
165 ms |
25792 KB |
Output is correct |
76 |
Correct |
183 ms |
25936 KB |
Output is correct |
77 |
Correct |
152 ms |
22204 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
212 KB |
Output is correct |
80 |
Correct |
3 ms |
596 KB |
Output is correct |
81 |
Correct |
68 ms |
8080 KB |
Output is correct |
82 |
Correct |
0 ms |
212 KB |
Output is correct |
83 |
Correct |
0 ms |
340 KB |
Output is correct |
84 |
Correct |
0 ms |
340 KB |
Output is correct |
85 |
Correct |
44 ms |
7596 KB |
Output is correct |
86 |
Correct |
59 ms |
8092 KB |
Output is correct |
87 |
Correct |
59 ms |
8092 KB |
Output is correct |
88 |
Correct |
94 ms |
8084 KB |
Output is correct |
89 |
Correct |
63 ms |
8216 KB |
Output is correct |
90 |
Correct |
0 ms |
212 KB |
Output is correct |
91 |
Correct |
0 ms |
212 KB |
Output is correct |
92 |
Correct |
3 ms |
596 KB |
Output is correct |
93 |
Correct |
59 ms |
8084 KB |
Output is correct |
94 |
Correct |
1 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 |
14 ms |
2208 KB |
Output is correct |
98 |
Correct |
56 ms |
8092 KB |
Output is correct |
99 |
Correct |
55 ms |
8092 KB |
Output is correct |
100 |
Correct |
55 ms |
8096 KB |
Output is correct |
101 |
Correct |
58 ms |
8088 KB |
Output is correct |
102 |
Correct |
55 ms |
8092 KB |
Output is correct |
103 |
Correct |
54 ms |
8088 KB |
Output is correct |
104 |
Correct |
56 ms |
8076 KB |
Output is correct |
105 |
Correct |
61 ms |
8080 KB |
Output is correct |