#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int construct(vector<vector<int>> p)
{
int n = p.size();
vector<bool> used(n, false);
vector<vector<int>> adjmatrix(n, vector<int> (n, 0));
for(int i = 0; i < n; i++)
{
if(used[i]) continue;
//Collect the component:
vector<int> component(0);
for(int j = 0; j < n; j++)
{
if(p[i][j] == 3)
{
return 0;
}
if(p[i][j] > 0)
{
component.push_back(j);
used[j] = true;
}
}
for(int j : component)
{
if(count(p[j].begin(), p[j].end(), 0) != n- (int) component.size())
{
return 0;
}
for(int k : component)
{
if(p[k][j] == 0)
{
return 0;
}
}
}
//Build the forest:
vector<bool> tree(component.size(), false);
vector<vector<int>> forest(0);
for(int j = 0; j < (int) component.size(); j++)
{
if(tree[j]) continue;
vector<int> t(0);
for(int k = 0; k < (int) component.size(); k++)
{
if(p[component[j]][component[k]] == 1)
{
t.push_back(component[k]);
tree[k] = true;
}
}
forest.push_back(t);
//Build the tree:
for(int k = 0; k < (int) t.size()-1; k++)
{
adjmatrix[t[k]][t[k+1]] = 1;
adjmatrix[t[k+1]][t[k]] = 1;
}
}
//Test the partitioning:
for(int j = 0; j < (int) forest.size(); j++)
{
for(int a : forest[j])
{
for(int k = 0; k < (int) forest.size(); k++)
{
for(int b : forest[k])
{
if((k == j && p[a][b] != 1) ||
(k != j && p[a][b] != 2))
{
return 0;
}
}
}
}
}
//Connect the trees:
if(forest.size() == 2)
{
return 0;
}
if(forest.size() > 2)
{
for(int j = 0; j < (int) forest.size()-1; j++)
{
adjmatrix[forest[j][0]][forest[j+1][0]] = 1;
adjmatrix[forest[j+1][0]][forest[j][0]] = 1;
}
adjmatrix[forest[0][0]][forest[forest.size()-1][0]] = 1;
adjmatrix[forest[forest.size()-1][0]][forest[0][0]] = 1;
}
}
build(adjmatrix);
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1176 KB |
Output is correct |
7 |
Correct |
169 ms |
22040 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1176 KB |
Output is correct |
7 |
Correct |
169 ms |
22040 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
6 ms |
1108 KB |
Output is correct |
13 |
Correct |
152 ms |
22012 KB |
Output is correct |
14 |
Correct |
1 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 |
73 ms |
12040 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
38 ms |
5768 KB |
Output is correct |
21 |
Correct |
164 ms |
23932 KB |
Output is correct |
22 |
Correct |
155 ms |
23968 KB |
Output is correct |
23 |
Correct |
187 ms |
23924 KB |
Output is correct |
24 |
Correct |
153 ms |
23888 KB |
Output is correct |
25 |
Correct |
71 ms |
14064 KB |
Output is correct |
26 |
Correct |
67 ms |
14076 KB |
Output is correct |
27 |
Correct |
160 ms |
23940 KB |
Output is correct |
28 |
Correct |
156 ms |
23928 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 |
0 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 |
153 ms |
22028 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 |
1108 KB |
Output is correct |
13 |
Correct |
159 ms |
22020 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 |
724 KB |
Output is correct |
17 |
Correct |
77 ms |
12040 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 |
42 ms |
5656 KB |
Output is correct |
22 |
Correct |
159 ms |
23924 KB |
Output is correct |
23 |
Correct |
154 ms |
23916 KB |
Output is correct |
24 |
Correct |
165 ms |
23924 KB |
Output is correct |
25 |
Correct |
67 ms |
14068 KB |
Output is correct |
26 |
Correct |
72 ms |
14080 KB |
Output is correct |
27 |
Correct |
161 ms |
23944 KB |
Output is correct |
28 |
Correct |
192 ms |
23980 KB |
Output is correct |
29 |
Correct |
67 ms |
13996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
40 ms |
6220 KB |
Output is correct |
5 |
Correct |
156 ms |
23984 KB |
Output is correct |
6 |
Correct |
165 ms |
23972 KB |
Output is correct |
7 |
Correct |
162 ms |
23924 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
39 ms |
6212 KB |
Output is correct |
10 |
Correct |
162 ms |
23928 KB |
Output is correct |
11 |
Correct |
160 ms |
24008 KB |
Output is correct |
12 |
Correct |
168 ms |
23920 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
296 KB |
Output is correct |
16 |
Correct |
39 ms |
6232 KB |
Output is correct |
17 |
Correct |
156 ms |
23988 KB |
Output is correct |
18 |
Correct |
167 ms |
23948 KB |
Output is correct |
19 |
Correct |
153 ms |
23928 KB |
Output is correct |
20 |
Correct |
159 ms |
24008 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1176 KB |
Output is correct |
7 |
Correct |
169 ms |
22040 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
6 ms |
1108 KB |
Output is correct |
13 |
Correct |
152 ms |
22012 KB |
Output is correct |
14 |
Correct |
1 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 |
73 ms |
12040 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
38 ms |
5768 KB |
Output is correct |
21 |
Correct |
164 ms |
23932 KB |
Output is correct |
22 |
Correct |
155 ms |
23968 KB |
Output is correct |
23 |
Correct |
187 ms |
23924 KB |
Output is correct |
24 |
Correct |
153 ms |
23888 KB |
Output is correct |
25 |
Correct |
71 ms |
14064 KB |
Output is correct |
26 |
Correct |
67 ms |
14076 KB |
Output is correct |
27 |
Correct |
160 ms |
23940 KB |
Output is correct |
28 |
Correct |
156 ms |
23928 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 |
0 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 |
153 ms |
22028 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1108 KB |
Output is correct |
41 |
Correct |
159 ms |
22020 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 |
724 KB |
Output is correct |
45 |
Correct |
77 ms |
12040 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 |
42 ms |
5656 KB |
Output is correct |
50 |
Correct |
159 ms |
23924 KB |
Output is correct |
51 |
Correct |
154 ms |
23916 KB |
Output is correct |
52 |
Correct |
165 ms |
23924 KB |
Output is correct |
53 |
Correct |
67 ms |
14068 KB |
Output is correct |
54 |
Correct |
72 ms |
14080 KB |
Output is correct |
55 |
Correct |
161 ms |
23944 KB |
Output is correct |
56 |
Correct |
192 ms |
23980 KB |
Output is correct |
57 |
Correct |
67 ms |
13996 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 |
852 KB |
Output is correct |
61 |
Correct |
71 ms |
14068 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
39 ms |
6220 KB |
Output is correct |
66 |
Correct |
71 ms |
14068 KB |
Output is correct |
67 |
Correct |
68 ms |
14080 KB |
Output is correct |
68 |
Correct |
68 ms |
14080 KB |
Output is correct |
69 |
Correct |
69 ms |
14072 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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1176 KB |
Output is correct |
7 |
Correct |
169 ms |
22040 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
6 ms |
1108 KB |
Output is correct |
13 |
Correct |
152 ms |
22012 KB |
Output is correct |
14 |
Correct |
1 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 |
73 ms |
12040 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
38 ms |
5768 KB |
Output is correct |
21 |
Correct |
164 ms |
23932 KB |
Output is correct |
22 |
Correct |
155 ms |
23968 KB |
Output is correct |
23 |
Correct |
187 ms |
23924 KB |
Output is correct |
24 |
Correct |
153 ms |
23888 KB |
Output is correct |
25 |
Correct |
71 ms |
14064 KB |
Output is correct |
26 |
Correct |
67 ms |
14076 KB |
Output is correct |
27 |
Correct |
160 ms |
23940 KB |
Output is correct |
28 |
Correct |
156 ms |
23928 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 |
0 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 |
153 ms |
22028 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1108 KB |
Output is correct |
41 |
Correct |
159 ms |
22020 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 |
724 KB |
Output is correct |
45 |
Correct |
77 ms |
12040 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 |
42 ms |
5656 KB |
Output is correct |
50 |
Correct |
159 ms |
23924 KB |
Output is correct |
51 |
Correct |
154 ms |
23916 KB |
Output is correct |
52 |
Correct |
165 ms |
23924 KB |
Output is correct |
53 |
Correct |
67 ms |
14068 KB |
Output is correct |
54 |
Correct |
72 ms |
14080 KB |
Output is correct |
55 |
Correct |
161 ms |
23944 KB |
Output is correct |
56 |
Correct |
192 ms |
23980 KB |
Output is correct |
57 |
Correct |
67 ms |
13996 KB |
Output is correct |
58 |
Correct |
1 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 |
40 ms |
6220 KB |
Output is correct |
62 |
Correct |
156 ms |
23984 KB |
Output is correct |
63 |
Correct |
165 ms |
23972 KB |
Output is correct |
64 |
Correct |
162 ms |
23924 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
39 ms |
6212 KB |
Output is correct |
67 |
Correct |
162 ms |
23928 KB |
Output is correct |
68 |
Correct |
160 ms |
24008 KB |
Output is correct |
69 |
Correct |
168 ms |
23920 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
0 ms |
296 KB |
Output is correct |
73 |
Correct |
39 ms |
6232 KB |
Output is correct |
74 |
Correct |
156 ms |
23988 KB |
Output is correct |
75 |
Correct |
167 ms |
23948 KB |
Output is correct |
76 |
Correct |
153 ms |
23928 KB |
Output is correct |
77 |
Correct |
159 ms |
24008 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 |
852 KB |
Output is correct |
81 |
Correct |
71 ms |
14068 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
212 KB |
Output is correct |
84 |
Correct |
0 ms |
212 KB |
Output is correct |
85 |
Correct |
39 ms |
6220 KB |
Output is correct |
86 |
Correct |
71 ms |
14068 KB |
Output is correct |
87 |
Correct |
68 ms |
14080 KB |
Output is correct |
88 |
Correct |
68 ms |
14080 KB |
Output is correct |
89 |
Correct |
69 ms |
14072 KB |
Output is correct |
90 |
Correct |
0 ms |
212 KB |
Output is correct |
91 |
Correct |
0 ms |
300 KB |
Output is correct |
92 |
Correct |
3 ms |
852 KB |
Output is correct |
93 |
Correct |
69 ms |
14080 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 |
296 KB |
Output is correct |
97 |
Correct |
18 ms |
3668 KB |
Output is correct |
98 |
Correct |
70 ms |
14072 KB |
Output is correct |
99 |
Correct |
70 ms |
14072 KB |
Output is correct |
100 |
Correct |
68 ms |
14028 KB |
Output is correct |
101 |
Correct |
67 ms |
14064 KB |
Output is correct |
102 |
Correct |
68 ms |
14076 KB |
Output is correct |
103 |
Correct |
68 ms |
14064 KB |
Output is correct |
104 |
Correct |
68 ms |
14156 KB |
Output is correct |
105 |
Correct |
74 ms |
14064 KB |
Output is correct |