#include "supertrees.h"
#include <string.h>
using namespace std;
typedef vector<int> vi;
const int N = 1000;
int abs_(int a) { return a > 0 ? a : -a; }
int ds[N];
int find(int i) {
return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
}
void join(int i, int j) {
i = find(i);
j = find(j);
if (i == j)
return;
if (ds[i] > ds[j])
ds[i] = j;
else {
if (ds[i] == ds[j])
ds[i]--;
ds[j] = i;
}
}
char root[N];
int construct(vector<vi> pp) {
int n = pp.size(), i, j, k;
vector<vi> aa(n);
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (pp[i][j] == 3)
return 0;
for (i = 0; i < n; i++)
aa[i].resize(n);
memset(ds, -1, n * sizeof *ds);
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (pp[i][j] == 1)
join(i, j);
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if ((find(i) == find(j)) != (pp[i][j] == 1))
return 0;
for (i = 0; i < n; i++)
if ((j = find(i)) != i)
aa[i][j] = aa[j][i] = 1;
else
root[i] = 1;
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (pp[i][j] == 2)
join(i, j);
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if ((find(i) == find(j)) != (pp[i][j] != 0))
return 0;
for (i = 0; i < n; i++)
if (root[i]) {
int c;
root[i] = 0;
k = i, c = 1;
for (j = 0; j < n; j++)
if (root[j] && find(j) == find(i))
root[j] = 0, aa[j][k] = aa[k][j] = 1, k = j, c++;
if (c == 2)
return 0;
if (k != i)
aa[i][k] = aa[k][i] = 1, k = j;
}
build(aa);
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1228 KB |
Output is correct |
7 |
Correct |
251 ms |
22440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1228 KB |
Output is correct |
7 |
Correct |
251 ms |
22440 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1236 KB |
Output is correct |
13 |
Correct |
286 ms |
22460 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
7 ms |
812 KB |
Output is correct |
17 |
Correct |
116 ms |
12520 KB |
Output is correct |
18 |
Correct |
0 ms |
288 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
75 ms |
6084 KB |
Output is correct |
21 |
Correct |
250 ms |
22460 KB |
Output is correct |
22 |
Correct |
330 ms |
22468 KB |
Output is correct |
23 |
Correct |
274 ms |
22480 KB |
Output is correct |
24 |
Correct |
259 ms |
22388 KB |
Output is correct |
25 |
Correct |
107 ms |
12448 KB |
Output is correct |
26 |
Correct |
105 ms |
12552 KB |
Output is correct |
27 |
Correct |
259 ms |
22468 KB |
Output is correct |
28 |
Correct |
256 ms |
22476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
288 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
10 ms |
1164 KB |
Output is correct |
9 |
Correct |
246 ms |
22296 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
10 ms |
1244 KB |
Output is correct |
13 |
Correct |
277 ms |
22224 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
284 KB |
Output is correct |
16 |
Correct |
6 ms |
772 KB |
Output is correct |
17 |
Correct |
117 ms |
12348 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
61 ms |
6088 KB |
Output is correct |
22 |
Correct |
250 ms |
22272 KB |
Output is correct |
23 |
Correct |
246 ms |
22280 KB |
Output is correct |
24 |
Correct |
254 ms |
22260 KB |
Output is correct |
25 |
Correct |
114 ms |
12320 KB |
Output is correct |
26 |
Correct |
113 ms |
12332 KB |
Output is correct |
27 |
Correct |
246 ms |
22288 KB |
Output is correct |
28 |
Correct |
259 ms |
22236 KB |
Output is correct |
29 |
Correct |
113 ms |
12356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
68 ms |
6044 KB |
Output is correct |
5 |
Correct |
243 ms |
22212 KB |
Output is correct |
6 |
Correct |
262 ms |
22224 KB |
Output is correct |
7 |
Correct |
251 ms |
22276 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
71 ms |
6048 KB |
Output is correct |
10 |
Correct |
241 ms |
22280 KB |
Output is correct |
11 |
Correct |
246 ms |
22340 KB |
Output is correct |
12 |
Correct |
252 ms |
22312 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
62 ms |
6008 KB |
Output is correct |
17 |
Correct |
250 ms |
22352 KB |
Output is correct |
18 |
Correct |
248 ms |
22464 KB |
Output is correct |
19 |
Correct |
251 ms |
22344 KB |
Output is correct |
20 |
Correct |
253 ms |
22352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1228 KB |
Output is correct |
7 |
Correct |
251 ms |
22440 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1236 KB |
Output is correct |
13 |
Correct |
286 ms |
22460 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
7 ms |
812 KB |
Output is correct |
17 |
Correct |
116 ms |
12520 KB |
Output is correct |
18 |
Correct |
0 ms |
288 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
75 ms |
6084 KB |
Output is correct |
21 |
Correct |
250 ms |
22460 KB |
Output is correct |
22 |
Correct |
330 ms |
22468 KB |
Output is correct |
23 |
Correct |
274 ms |
22480 KB |
Output is correct |
24 |
Correct |
259 ms |
22388 KB |
Output is correct |
25 |
Correct |
107 ms |
12448 KB |
Output is correct |
26 |
Correct |
105 ms |
12552 KB |
Output is correct |
27 |
Correct |
259 ms |
22468 KB |
Output is correct |
28 |
Correct |
256 ms |
22476 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
288 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
10 ms |
1164 KB |
Output is correct |
37 |
Correct |
246 ms |
22296 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1244 KB |
Output is correct |
41 |
Correct |
277 ms |
22224 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
284 KB |
Output is correct |
44 |
Correct |
6 ms |
772 KB |
Output is correct |
45 |
Correct |
117 ms |
12348 KB |
Output is correct |
46 |
Correct |
0 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
61 ms |
6088 KB |
Output is correct |
50 |
Correct |
250 ms |
22272 KB |
Output is correct |
51 |
Correct |
246 ms |
22280 KB |
Output is correct |
52 |
Correct |
254 ms |
22260 KB |
Output is correct |
53 |
Correct |
114 ms |
12320 KB |
Output is correct |
54 |
Correct |
113 ms |
12332 KB |
Output is correct |
55 |
Correct |
246 ms |
22288 KB |
Output is correct |
56 |
Correct |
259 ms |
22236 KB |
Output is correct |
57 |
Correct |
113 ms |
12356 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
5 ms |
844 KB |
Output is correct |
61 |
Correct |
121 ms |
12480 KB |
Output is correct |
62 |
Correct |
0 ms |
204 KB |
Output is correct |
63 |
Correct |
1 ms |
204 KB |
Output is correct |
64 |
Correct |
0 ms |
204 KB |
Output is correct |
65 |
Correct |
61 ms |
6068 KB |
Output is correct |
66 |
Correct |
110 ms |
12432 KB |
Output is correct |
67 |
Correct |
106 ms |
12484 KB |
Output is correct |
68 |
Correct |
111 ms |
12476 KB |
Output is correct |
69 |
Correct |
138 ms |
12460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
284 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1228 KB |
Output is correct |
7 |
Correct |
251 ms |
22440 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
11 ms |
1236 KB |
Output is correct |
13 |
Correct |
286 ms |
22460 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
7 ms |
812 KB |
Output is correct |
17 |
Correct |
116 ms |
12520 KB |
Output is correct |
18 |
Correct |
0 ms |
288 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
75 ms |
6084 KB |
Output is correct |
21 |
Correct |
250 ms |
22460 KB |
Output is correct |
22 |
Correct |
330 ms |
22468 KB |
Output is correct |
23 |
Correct |
274 ms |
22480 KB |
Output is correct |
24 |
Correct |
259 ms |
22388 KB |
Output is correct |
25 |
Correct |
107 ms |
12448 KB |
Output is correct |
26 |
Correct |
105 ms |
12552 KB |
Output is correct |
27 |
Correct |
259 ms |
22468 KB |
Output is correct |
28 |
Correct |
256 ms |
22476 KB |
Output is correct |
29 |
Correct |
0 ms |
204 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
288 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
0 ms |
204 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
10 ms |
1164 KB |
Output is correct |
37 |
Correct |
246 ms |
22296 KB |
Output is correct |
38 |
Correct |
0 ms |
204 KB |
Output is correct |
39 |
Correct |
0 ms |
204 KB |
Output is correct |
40 |
Correct |
10 ms |
1244 KB |
Output is correct |
41 |
Correct |
277 ms |
22224 KB |
Output is correct |
42 |
Correct |
0 ms |
204 KB |
Output is correct |
43 |
Correct |
0 ms |
284 KB |
Output is correct |
44 |
Correct |
6 ms |
772 KB |
Output is correct |
45 |
Correct |
117 ms |
12348 KB |
Output is correct |
46 |
Correct |
0 ms |
204 KB |
Output is correct |
47 |
Correct |
0 ms |
204 KB |
Output is correct |
48 |
Correct |
0 ms |
204 KB |
Output is correct |
49 |
Correct |
61 ms |
6088 KB |
Output is correct |
50 |
Correct |
250 ms |
22272 KB |
Output is correct |
51 |
Correct |
246 ms |
22280 KB |
Output is correct |
52 |
Correct |
254 ms |
22260 KB |
Output is correct |
53 |
Correct |
114 ms |
12320 KB |
Output is correct |
54 |
Correct |
113 ms |
12332 KB |
Output is correct |
55 |
Correct |
246 ms |
22288 KB |
Output is correct |
56 |
Correct |
259 ms |
22236 KB |
Output is correct |
57 |
Correct |
113 ms |
12356 KB |
Output is correct |
58 |
Correct |
0 ms |
204 KB |
Output is correct |
59 |
Correct |
0 ms |
204 KB |
Output is correct |
60 |
Correct |
0 ms |
204 KB |
Output is correct |
61 |
Correct |
68 ms |
6044 KB |
Output is correct |
62 |
Correct |
243 ms |
22212 KB |
Output is correct |
63 |
Correct |
262 ms |
22224 KB |
Output is correct |
64 |
Correct |
251 ms |
22276 KB |
Output is correct |
65 |
Correct |
1 ms |
204 KB |
Output is correct |
66 |
Correct |
71 ms |
6048 KB |
Output is correct |
67 |
Correct |
241 ms |
22280 KB |
Output is correct |
68 |
Correct |
246 ms |
22340 KB |
Output is correct |
69 |
Correct |
252 ms |
22312 KB |
Output is correct |
70 |
Correct |
0 ms |
204 KB |
Output is correct |
71 |
Correct |
0 ms |
204 KB |
Output is correct |
72 |
Correct |
0 ms |
204 KB |
Output is correct |
73 |
Correct |
62 ms |
6008 KB |
Output is correct |
74 |
Correct |
250 ms |
22352 KB |
Output is correct |
75 |
Correct |
248 ms |
22464 KB |
Output is correct |
76 |
Correct |
251 ms |
22344 KB |
Output is correct |
77 |
Correct |
253 ms |
22352 KB |
Output is correct |
78 |
Correct |
0 ms |
204 KB |
Output is correct |
79 |
Correct |
0 ms |
204 KB |
Output is correct |
80 |
Correct |
5 ms |
844 KB |
Output is correct |
81 |
Correct |
121 ms |
12480 KB |
Output is correct |
82 |
Correct |
0 ms |
204 KB |
Output is correct |
83 |
Correct |
1 ms |
204 KB |
Output is correct |
84 |
Correct |
0 ms |
204 KB |
Output is correct |
85 |
Correct |
61 ms |
6068 KB |
Output is correct |
86 |
Correct |
110 ms |
12432 KB |
Output is correct |
87 |
Correct |
106 ms |
12484 KB |
Output is correct |
88 |
Correct |
111 ms |
12476 KB |
Output is correct |
89 |
Correct |
138 ms |
12460 KB |
Output is correct |
90 |
Correct |
0 ms |
204 KB |
Output is correct |
91 |
Correct |
0 ms |
204 KB |
Output is correct |
92 |
Correct |
5 ms |
588 KB |
Output is correct |
93 |
Correct |
108 ms |
8620 KB |
Output is correct |
94 |
Correct |
1 ms |
204 KB |
Output is correct |
95 |
Correct |
1 ms |
204 KB |
Output is correct |
96 |
Correct |
0 ms |
204 KB |
Output is correct |
97 |
Correct |
26 ms |
2660 KB |
Output is correct |
98 |
Correct |
105 ms |
10100 KB |
Output is correct |
99 |
Correct |
128 ms |
10104 KB |
Output is correct |
100 |
Correct |
120 ms |
10096 KB |
Output is correct |
101 |
Correct |
105 ms |
10100 KB |
Output is correct |
102 |
Correct |
105 ms |
10180 KB |
Output is correct |
103 |
Correct |
105 ms |
10052 KB |
Output is correct |
104 |
Correct |
104 ms |
10084 KB |
Output is correct |
105 |
Correct |
110 ms |
10100 KB |
Output is correct |