#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() <= 3 && 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: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++)
| ~~^~~~~~~~~~~~~
# |
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 |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1208 KB |
Output is correct |
7 |
Correct |
153 ms |
24020 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 |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1208 KB |
Output is correct |
7 |
Correct |
153 ms |
24020 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1236 KB |
Output is correct |
13 |
Correct |
152 ms |
23936 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
816 KB |
Output is correct |
17 |
Correct |
83 ms |
14068 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
296 KB |
Output is correct |
20 |
Correct |
49 ms |
6260 KB |
Output is correct |
21 |
Correct |
152 ms |
23940 KB |
Output is correct |
22 |
Correct |
151 ms |
23928 KB |
Output is correct |
23 |
Correct |
179 ms |
23968 KB |
Output is correct |
24 |
Correct |
149 ms |
23984 KB |
Output is correct |
25 |
Correct |
73 ms |
14072 KB |
Output is correct |
26 |
Correct |
63 ms |
14072 KB |
Output is correct |
27 |
Correct |
157 ms |
23956 KB |
Output is correct |
28 |
Correct |
151 ms |
23992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
38 ms |
6384 KB |
Output is correct |
5 |
Correct |
151 ms |
23932 KB |
Output is correct |
6 |
Correct |
147 ms |
23932 KB |
Output is correct |
7 |
Correct |
161 ms |
23976 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
37 ms |
6244 KB |
Output is correct |
10 |
Correct |
159 ms |
23932 KB |
Output is correct |
11 |
Correct |
151 ms |
24000 KB |
Output is correct |
12 |
Correct |
155 ms |
24004 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
38 ms |
6260 KB |
Output is correct |
17 |
Correct |
160 ms |
23972 KB |
Output is correct |
18 |
Correct |
150 ms |
24012 KB |
Output is correct |
19 |
Correct |
145 ms |
23924 KB |
Output is correct |
20 |
Correct |
150 ms |
23924 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 |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1208 KB |
Output is correct |
7 |
Correct |
153 ms |
24020 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1236 KB |
Output is correct |
13 |
Correct |
152 ms |
23936 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
816 KB |
Output is correct |
17 |
Correct |
83 ms |
14068 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
296 KB |
Output is correct |
20 |
Correct |
49 ms |
6260 KB |
Output is correct |
21 |
Correct |
152 ms |
23940 KB |
Output is correct |
22 |
Correct |
151 ms |
23928 KB |
Output is correct |
23 |
Correct |
179 ms |
23968 KB |
Output is correct |
24 |
Correct |
149 ms |
23984 KB |
Output is correct |
25 |
Correct |
73 ms |
14072 KB |
Output is correct |
26 |
Correct |
63 ms |
14072 KB |
Output is correct |
27 |
Correct |
157 ms |
23956 KB |
Output is correct |
28 |
Correct |
151 ms |
23992 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
300 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1208 KB |
Output is correct |
7 |
Correct |
153 ms |
24020 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
1236 KB |
Output is correct |
13 |
Correct |
152 ms |
23936 KB |
Output is correct |
14 |
Correct |
1 ms |
296 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
816 KB |
Output is correct |
17 |
Correct |
83 ms |
14068 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
296 KB |
Output is correct |
20 |
Correct |
49 ms |
6260 KB |
Output is correct |
21 |
Correct |
152 ms |
23940 KB |
Output is correct |
22 |
Correct |
151 ms |
23928 KB |
Output is correct |
23 |
Correct |
179 ms |
23968 KB |
Output is correct |
24 |
Correct |
149 ms |
23984 KB |
Output is correct |
25 |
Correct |
73 ms |
14072 KB |
Output is correct |
26 |
Correct |
63 ms |
14072 KB |
Output is correct |
27 |
Correct |
157 ms |
23956 KB |
Output is correct |
28 |
Correct |
151 ms |
23992 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |