#include "supertrees.h"
#include <vector>
#include <iostream>
using namespace std;
vector<int> cc, cc2, rr;
int n;
vector<int> used, used2;
void dfs(int v, const vector<vector<int>>& g)
{
used[v] = true;
cc.push_back(v);
for(int u = 0; u < n; u++) if(g[v][u] && !used[u])
dfs(u, g);
}
void dfs2(int v, const vector<vector<int>>& g)
{
used2[v] = true;
cc2.push_back(v);
for(int u = 0; u < n; u++) if(g[v][u] == 1 && !used2[u])
dfs2(u, g);
}
int construct(std::vector<std::vector<int>> p) {
n = p.size();
for(int a = 0; a < n; a++)
for(int b = 0; b < n; b++)
if(p[a][b] != p[b][a])
return 0;
vector<vector<int>> ans(n, vector<int>(n, 0));
used.assign(n, 0);
for(int i = 0; i < n; i++) if(!used[i])
{
cc.clear();
dfs(i, p);
used2.assign(n, 0);
rr.clear();
for(int j : cc) if(!used2[j])
{
cc2.clear();
dfs2(j, p);
/// Check not dif on cc of 1
for(auto a : cc2)
for(auto b : cc2) if(a != b)
{
if(p[a][b] != 1)
return 0;
}
for(int k = 0; k < cc2.size()-1; k++)
{
ans[cc2[k]][cc2[k+1]] = 1;
ans[cc2[k+1]][cc2[k]] = 1;
}
rr.push_back(j);
}
if(rr.size() == 1)
continue;
int typ = p[rr[0]][rr[1]];
if(rr.size() <= typ)
return 0;
if(typ == 3)
return 0;
for(auto a : rr)
{
for(auto b : rr) if(a != b)
{
if(p[a][b] != typ)
{
return 0;
}
}
}
if(typ == 2)
{
for(int j = 0; j < rr.size()-1; j++)
{
ans[rr[j]][rr[j+1]] = 1;
ans[rr[j+1]][rr[j]] = 1;
}
ans[rr[0]][rr[rr.size()-1]] = 1;
ans[rr[rr.size()-1]][rr[0]] = 1;
}
if(typ == 3)
{
for(int j = 0; j < rr.size()-2; j++)
{
ans[rr[j]][rr[j+1]] = 1;
ans[rr[j+1]][rr[j]] = 1;
}
ans[rr[0]][rr[rr.size()-2]] = 1;
ans[rr[rr.size()-2]][rr[0]] = 1;
ans[rr[0]][rr[rr.size()-1]] = 1;
ans[rr[rr.size()-1]][rr[0]] = 1;
ans[rr[1]][rr[rr.size()-1]] = 1;
ans[rr[rr.size()-1]][rr[1]] = 1;
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int k = 0; k < cc2.size()-1; k++)
| ~~^~~~~~~~~~~~~~
supertrees.cpp:73:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
73 | if(rr.size() <= typ)
| ~~~~~~~~~~^~~~~~
supertrees.cpp:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for(int j = 0; j < rr.size()-1; j++)
| ~~^~~~~~~~~~~~~
supertrees.cpp:103:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int j = 0; j < rr.size()-2; j++)
| ~~^~~~~~~~~~~~~
# |
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 |
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 |
6 ms |
1108 KB |
Output is correct |
7 |
Correct |
155 ms |
22008 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 |
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 |
6 ms |
1108 KB |
Output is correct |
7 |
Correct |
155 ms |
22008 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 |
167 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 |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
82 ms |
12108 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
5648 KB |
Output is correct |
21 |
Correct |
154 ms |
22032 KB |
Output is correct |
22 |
Correct |
163 ms |
21984 KB |
Output is correct |
23 |
Correct |
162 ms |
22032 KB |
Output is correct |
24 |
Correct |
155 ms |
21980 KB |
Output is correct |
25 |
Correct |
64 ms |
12036 KB |
Output is correct |
26 |
Correct |
61 ms |
12040 KB |
Output is correct |
27 |
Correct |
158 ms |
22028 KB |
Output is correct |
28 |
Correct |
159 ms |
22024 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 |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
9 ms |
1096 KB |
Output is correct |
9 |
Correct |
158 ms |
22108 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 |
1108 KB |
Output is correct |
13 |
Correct |
156 ms |
22140 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 |
720 KB |
Output is correct |
17 |
Correct |
89 ms |
12448 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
39 ms |
5788 KB |
Output is correct |
22 |
Correct |
154 ms |
22096 KB |
Output is correct |
23 |
Correct |
172 ms |
22216 KB |
Output is correct |
24 |
Correct |
172 ms |
22184 KB |
Output is correct |
25 |
Correct |
67 ms |
12164 KB |
Output is correct |
26 |
Correct |
65 ms |
12236 KB |
Output is correct |
27 |
Correct |
155 ms |
22136 KB |
Output is correct |
28 |
Correct |
158 ms |
22200 KB |
Output is correct |
29 |
Correct |
65 ms |
12188 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 |
5720 KB |
Output is correct |
5 |
Correct |
153 ms |
22020 KB |
Output is correct |
6 |
Correct |
155 ms |
21964 KB |
Output is correct |
7 |
Correct |
160 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
41 ms |
5740 KB |
Output is correct |
10 |
Correct |
158 ms |
22024 KB |
Output is correct |
11 |
Correct |
158 ms |
22020 KB |
Output is correct |
12 |
Correct |
164 ms |
22288 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 |
212 KB |
Output is correct |
16 |
Correct |
40 ms |
5704 KB |
Output is correct |
17 |
Correct |
154 ms |
22024 KB |
Output is correct |
18 |
Correct |
158 ms |
22044 KB |
Output is correct |
19 |
Correct |
156 ms |
22052 KB |
Output is correct |
20 |
Correct |
159 ms |
22020 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 |
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 |
6 ms |
1108 KB |
Output is correct |
7 |
Correct |
155 ms |
22008 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 |
167 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 |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
82 ms |
12108 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
5648 KB |
Output is correct |
21 |
Correct |
154 ms |
22032 KB |
Output is correct |
22 |
Correct |
163 ms |
21984 KB |
Output is correct |
23 |
Correct |
162 ms |
22032 KB |
Output is correct |
24 |
Correct |
155 ms |
21980 KB |
Output is correct |
25 |
Correct |
64 ms |
12036 KB |
Output is correct |
26 |
Correct |
61 ms |
12040 KB |
Output is correct |
27 |
Correct |
158 ms |
22028 KB |
Output is correct |
28 |
Correct |
159 ms |
22024 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 |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
9 ms |
1096 KB |
Output is correct |
37 |
Correct |
158 ms |
22108 KB |
Output is correct |
38 |
Correct |
0 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 |
156 ms |
22140 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
720 KB |
Output is correct |
45 |
Correct |
89 ms |
12448 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
39 ms |
5788 KB |
Output is correct |
50 |
Correct |
154 ms |
22096 KB |
Output is correct |
51 |
Correct |
172 ms |
22216 KB |
Output is correct |
52 |
Correct |
172 ms |
22184 KB |
Output is correct |
53 |
Correct |
67 ms |
12164 KB |
Output is correct |
54 |
Correct |
65 ms |
12236 KB |
Output is correct |
55 |
Correct |
155 ms |
22136 KB |
Output is correct |
56 |
Correct |
158 ms |
22200 KB |
Output is correct |
57 |
Correct |
65 ms |
12188 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
724 KB |
Output is correct |
61 |
Correct |
77 ms |
12328 KB |
Output is correct |
62 |
Correct |
0 ms |
212 KB |
Output is correct |
63 |
Correct |
0 ms |
212 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
40 ms |
5792 KB |
Output is correct |
66 |
Correct |
66 ms |
12236 KB |
Output is correct |
67 |
Correct |
67 ms |
12192 KB |
Output is correct |
68 |
Correct |
64 ms |
12184 KB |
Output is correct |
69 |
Correct |
64 ms |
12248 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 |
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 |
6 ms |
1108 KB |
Output is correct |
7 |
Correct |
155 ms |
22008 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 |
167 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 |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
82 ms |
12108 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
39 ms |
5648 KB |
Output is correct |
21 |
Correct |
154 ms |
22032 KB |
Output is correct |
22 |
Correct |
163 ms |
21984 KB |
Output is correct |
23 |
Correct |
162 ms |
22032 KB |
Output is correct |
24 |
Correct |
155 ms |
21980 KB |
Output is correct |
25 |
Correct |
64 ms |
12036 KB |
Output is correct |
26 |
Correct |
61 ms |
12040 KB |
Output is correct |
27 |
Correct |
158 ms |
22028 KB |
Output is correct |
28 |
Correct |
159 ms |
22024 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 |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
9 ms |
1096 KB |
Output is correct |
37 |
Correct |
158 ms |
22108 KB |
Output is correct |
38 |
Correct |
0 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 |
156 ms |
22140 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
4 ms |
720 KB |
Output is correct |
45 |
Correct |
89 ms |
12448 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
39 ms |
5788 KB |
Output is correct |
50 |
Correct |
154 ms |
22096 KB |
Output is correct |
51 |
Correct |
172 ms |
22216 KB |
Output is correct |
52 |
Correct |
172 ms |
22184 KB |
Output is correct |
53 |
Correct |
67 ms |
12164 KB |
Output is correct |
54 |
Correct |
65 ms |
12236 KB |
Output is correct |
55 |
Correct |
155 ms |
22136 KB |
Output is correct |
56 |
Correct |
158 ms |
22200 KB |
Output is correct |
57 |
Correct |
65 ms |
12188 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 |
5720 KB |
Output is correct |
62 |
Correct |
153 ms |
22020 KB |
Output is correct |
63 |
Correct |
155 ms |
21964 KB |
Output is correct |
64 |
Correct |
160 ms |
22020 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
41 ms |
5740 KB |
Output is correct |
67 |
Correct |
158 ms |
22024 KB |
Output is correct |
68 |
Correct |
158 ms |
22020 KB |
Output is correct |
69 |
Correct |
164 ms |
22288 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 |
212 KB |
Output is correct |
73 |
Correct |
40 ms |
5704 KB |
Output is correct |
74 |
Correct |
154 ms |
22024 KB |
Output is correct |
75 |
Correct |
158 ms |
22044 KB |
Output is correct |
76 |
Correct |
156 ms |
22052 KB |
Output is correct |
77 |
Correct |
159 ms |
22020 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
0 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
724 KB |
Output is correct |
81 |
Correct |
77 ms |
12328 KB |
Output is correct |
82 |
Correct |
0 ms |
212 KB |
Output is correct |
83 |
Correct |
0 ms |
212 KB |
Output is correct |
84 |
Correct |
0 ms |
212 KB |
Output is correct |
85 |
Correct |
40 ms |
5792 KB |
Output is correct |
86 |
Correct |
66 ms |
12236 KB |
Output is correct |
87 |
Correct |
67 ms |
12192 KB |
Output is correct |
88 |
Correct |
64 ms |
12184 KB |
Output is correct |
89 |
Correct |
64 ms |
12248 KB |
Output is correct |
90 |
Correct |
0 ms |
212 KB |
Output is correct |
91 |
Correct |
0 ms |
212 KB |
Output is correct |
92 |
Correct |
4 ms |
724 KB |
Output is correct |
93 |
Correct |
77 ms |
12320 KB |
Output is correct |
94 |
Correct |
0 ms |
212 KB |
Output is correct |
95 |
Correct |
0 ms |
212 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
17 ms |
3220 KB |
Output is correct |
98 |
Correct |
65 ms |
12160 KB |
Output is correct |
99 |
Correct |
66 ms |
12216 KB |
Output is correct |
100 |
Correct |
68 ms |
12168 KB |
Output is correct |
101 |
Correct |
67 ms |
12184 KB |
Output is correct |
102 |
Correct |
68 ms |
12236 KB |
Output is correct |
103 |
Correct |
68 ms |
14068 KB |
Output is correct |
104 |
Correct |
74 ms |
14068 KB |
Output is correct |
105 |
Correct |
79 ms |
14076 KB |
Output is correct |