#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;
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:90:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(int j = 0; j < rr.size()-1; j++)
| ~~^~~~~~~~~~~~~
supertrees.cpp:100:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for(int j = 0; j < rr.size()-2; j++)
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
154 ms |
22024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
154 ms |
22024 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 |
7 ms |
1132 KB |
Output is correct |
13 |
Correct |
148 ms |
22032 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 |
724 KB |
Output is correct |
17 |
Correct |
80 ms |
12164 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 |
5752 KB |
Output is correct |
21 |
Correct |
151 ms |
21964 KB |
Output is correct |
22 |
Correct |
187 ms |
22020 KB |
Output is correct |
23 |
Correct |
161 ms |
22072 KB |
Output is correct |
24 |
Correct |
150 ms |
22032 KB |
Output is correct |
25 |
Correct |
64 ms |
12108 KB |
Output is correct |
26 |
Correct |
62 ms |
12036 KB |
Output is correct |
27 |
Correct |
159 ms |
22036 KB |
Output is correct |
28 |
Correct |
157 ms |
21964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
1236 KB |
Output is correct |
9 |
Correct |
147 ms |
23940 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
7 ms |
1236 KB |
Output is correct |
13 |
Correct |
181 ms |
23992 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
824 KB |
Output is correct |
17 |
Correct |
74 ms |
14076 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
300 KB |
Output is correct |
20 |
Correct |
0 ms |
296 KB |
Output is correct |
21 |
Correct |
38 ms |
6200 KB |
Output is correct |
22 |
Correct |
155 ms |
23936 KB |
Output is correct |
23 |
Correct |
151 ms |
24012 KB |
Output is correct |
24 |
Correct |
155 ms |
24016 KB |
Output is correct |
25 |
Correct |
73 ms |
14088 KB |
Output is correct |
26 |
Correct |
63 ms |
14080 KB |
Output is correct |
27 |
Correct |
146 ms |
23948 KB |
Output is correct |
28 |
Correct |
158 ms |
24084 KB |
Output is correct |
29 |
Correct |
65 ms |
14080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
39 ms |
5728 KB |
Output is correct |
5 |
Correct |
157 ms |
21968 KB |
Output is correct |
6 |
Correct |
150 ms |
22028 KB |
Output is correct |
7 |
Correct |
155 ms |
22020 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
38 ms |
5764 KB |
Output is correct |
10 |
Correct |
151 ms |
21984 KB |
Output is correct |
11 |
Correct |
153 ms |
22020 KB |
Output is correct |
12 |
Correct |
153 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 |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
37 ms |
5732 KB |
Output is correct |
17 |
Correct |
148 ms |
21952 KB |
Output is correct |
18 |
Correct |
152 ms |
22024 KB |
Output is correct |
19 |
Correct |
152 ms |
22020 KB |
Output is correct |
20 |
Correct |
154 ms |
22012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
154 ms |
22024 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 |
7 ms |
1132 KB |
Output is correct |
13 |
Correct |
148 ms |
22032 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 |
724 KB |
Output is correct |
17 |
Correct |
80 ms |
12164 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 |
5752 KB |
Output is correct |
21 |
Correct |
151 ms |
21964 KB |
Output is correct |
22 |
Correct |
187 ms |
22020 KB |
Output is correct |
23 |
Correct |
161 ms |
22072 KB |
Output is correct |
24 |
Correct |
150 ms |
22032 KB |
Output is correct |
25 |
Correct |
64 ms |
12108 KB |
Output is correct |
26 |
Correct |
62 ms |
12036 KB |
Output is correct |
27 |
Correct |
159 ms |
22036 KB |
Output is correct |
28 |
Correct |
157 ms |
21964 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 |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
6 ms |
1236 KB |
Output is correct |
37 |
Correct |
147 ms |
23940 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
181 ms |
23992 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
824 KB |
Output is correct |
45 |
Correct |
74 ms |
14076 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
300 KB |
Output is correct |
48 |
Correct |
0 ms |
296 KB |
Output is correct |
49 |
Correct |
38 ms |
6200 KB |
Output is correct |
50 |
Correct |
155 ms |
23936 KB |
Output is correct |
51 |
Correct |
151 ms |
24012 KB |
Output is correct |
52 |
Correct |
155 ms |
24016 KB |
Output is correct |
53 |
Correct |
73 ms |
14088 KB |
Output is correct |
54 |
Correct |
63 ms |
14080 KB |
Output is correct |
55 |
Correct |
146 ms |
23948 KB |
Output is correct |
56 |
Correct |
158 ms |
24084 KB |
Output is correct |
57 |
Correct |
65 ms |
14080 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
4 ms |
852 KB |
Output is correct |
61 |
Correct |
76 ms |
14072 KB |
Output is correct |
62 |
Correct |
0 ms |
300 KB |
Output is correct |
63 |
Correct |
1 ms |
296 KB |
Output is correct |
64 |
Correct |
0 ms |
212 KB |
Output is correct |
65 |
Correct |
38 ms |
6228 KB |
Output is correct |
66 |
Correct |
64 ms |
14028 KB |
Output is correct |
67 |
Correct |
65 ms |
14068 KB |
Output is correct |
68 |
Correct |
63 ms |
14088 KB |
Output is correct |
69 |
Correct |
62 ms |
14072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
154 ms |
22024 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 |
7 ms |
1132 KB |
Output is correct |
13 |
Correct |
148 ms |
22032 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 |
724 KB |
Output is correct |
17 |
Correct |
80 ms |
12164 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 |
5752 KB |
Output is correct |
21 |
Correct |
151 ms |
21964 KB |
Output is correct |
22 |
Correct |
187 ms |
22020 KB |
Output is correct |
23 |
Correct |
161 ms |
22072 KB |
Output is correct |
24 |
Correct |
150 ms |
22032 KB |
Output is correct |
25 |
Correct |
64 ms |
12108 KB |
Output is correct |
26 |
Correct |
62 ms |
12036 KB |
Output is correct |
27 |
Correct |
159 ms |
22036 KB |
Output is correct |
28 |
Correct |
157 ms |
21964 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 |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
6 ms |
1236 KB |
Output is correct |
37 |
Correct |
147 ms |
23940 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
7 ms |
1236 KB |
Output is correct |
41 |
Correct |
181 ms |
23992 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
824 KB |
Output is correct |
45 |
Correct |
74 ms |
14076 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
300 KB |
Output is correct |
48 |
Correct |
0 ms |
296 KB |
Output is correct |
49 |
Correct |
38 ms |
6200 KB |
Output is correct |
50 |
Correct |
155 ms |
23936 KB |
Output is correct |
51 |
Correct |
151 ms |
24012 KB |
Output is correct |
52 |
Correct |
155 ms |
24016 KB |
Output is correct |
53 |
Correct |
73 ms |
14088 KB |
Output is correct |
54 |
Correct |
63 ms |
14080 KB |
Output is correct |
55 |
Correct |
146 ms |
23948 KB |
Output is correct |
56 |
Correct |
158 ms |
24084 KB |
Output is correct |
57 |
Correct |
65 ms |
14080 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 |
39 ms |
5728 KB |
Output is correct |
62 |
Correct |
157 ms |
21968 KB |
Output is correct |
63 |
Correct |
150 ms |
22028 KB |
Output is correct |
64 |
Correct |
155 ms |
22020 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
38 ms |
5764 KB |
Output is correct |
67 |
Correct |
151 ms |
21984 KB |
Output is correct |
68 |
Correct |
153 ms |
22020 KB |
Output is correct |
69 |
Correct |
153 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 |
0 ms |
212 KB |
Output is correct |
73 |
Correct |
37 ms |
5732 KB |
Output is correct |
74 |
Correct |
148 ms |
21952 KB |
Output is correct |
75 |
Correct |
152 ms |
22024 KB |
Output is correct |
76 |
Correct |
152 ms |
22020 KB |
Output is correct |
77 |
Correct |
154 ms |
22012 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
1 ms |
212 KB |
Output is correct |
80 |
Correct |
4 ms |
852 KB |
Output is correct |
81 |
Correct |
76 ms |
14072 KB |
Output is correct |
82 |
Correct |
0 ms |
300 KB |
Output is correct |
83 |
Correct |
1 ms |
296 KB |
Output is correct |
84 |
Correct |
0 ms |
212 KB |
Output is correct |
85 |
Correct |
38 ms |
6228 KB |
Output is correct |
86 |
Correct |
64 ms |
14028 KB |
Output is correct |
87 |
Correct |
65 ms |
14068 KB |
Output is correct |
88 |
Correct |
63 ms |
14088 KB |
Output is correct |
89 |
Correct |
62 ms |
14072 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
0 ms |
212 KB |
Output is correct |
92 |
Correct |
3 ms |
852 KB |
Output is correct |
93 |
Correct |
73 ms |
14084 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 |
15 ms |
3716 KB |
Output is correct |
98 |
Correct |
67 ms |
14080 KB |
Output is correct |
99 |
Correct |
65 ms |
14072 KB |
Output is correct |
100 |
Correct |
64 ms |
14068 KB |
Output is correct |
101 |
Correct |
63 ms |
14076 KB |
Output is correct |
102 |
Incorrect |
158 ms |
24224 KB |
Answer gives possible 1 while actual possible 0 |
103 |
Halted |
0 ms |
0 KB |
- |