#include "supertrees.h"
#include <vector>
#include<stdio.h>
#define pb push_back
const int N = 1005;
using namespace std;
int taken[N], compcnt = 1, n, have1[N], taken2[N];
vector<int>comp[N], idk[N], comp2[N];
vector<vector<int>>p;
bool checkValid()
{
for(int a = 1; a < compcnt; a++)
for(int b = 0; b < comp[a].size(); b++)
for(int c = 0; c < comp[a].size(); c++)
if(p[comp[a][b]][comp[a][c]] == 0 || p[comp[a][b]][comp[a][c]] == 3)
return false;
for(int a = 0; a < n; a++)
for(int b = 0; b < n; b++)
if(p[a][b] > 0 && taken[a] != taken[b])
return false;
return true;
}
int gettype(int i)
{
if(comp[i].size() == 1)
return 3;
int mini = 3;
int maxi = 0;
for(auto a:comp[i])
for(auto b:comp[i])
{
if(a == b)
continue;
mini=min(mini, p[a][b]);
maxi=max(maxi, p[a][b]);
}
if(mini == maxi)
{
if(mini == 1)
return 0;
else
return 1;
}
return 2;
}
int construct(vector<vector<int>> pp) {
p = pp;
n = p.size();
vector<vector<int>> answer;
for (int i = 0; i < n; i++) {
vector<int> row;
row.resize(n);
answer.push_back(row);
}
// printf("1\n");
for(int a = 0; a < n; a++)
{
if(taken[a])
continue;
for(int b = 0; b < n; b++)
if(p[a][b])
{
// printf("%d ", b);
comp[compcnt].pb(b);
taken[b] = compcnt;
}
// printf("\n");
compcnt++;
}
// for(int a = 0; a < n; a++)
// printf("%d: %d\n", a, taken[a]);
// printf("2\n");
if(!checkValid())
return 0;
// printf("3\n");
for(int i = 1; i < compcnt; i++)
{
// printf("4\n");
int x = gettype(i);
if(x == 0)
{
for(int a = 1; a < comp[i].size(); a++)
answer[comp[i][a]][comp[i][a - 1]] = answer[comp[i][a - 1]][comp[i][a]] = 1;
}
else if(x == 1)
{
if(comp[i].size() < 3)
return 0;
for(int a = 1; a <= comp[i].size(); a++)
{
int x = comp[i][a % comp[i].size()];
int y = comp[i][a - 1];
answer[x][y] = answer[y][x] = 1;
}
}
else if(x == 2)
{
// printf("here\n");
int cnt = 0;
for(auto a: comp[i])
if(!taken2[a])
{
// printf("%d\n", a);
cnt++;
for(auto b: comp[i])
{
if(p[a][b] == 1)
{
comp2[cnt].pb(b);
taken2[b] = cnt;
}
}
}
if(cnt < 3)
return 0;
// printf("here\n");
for(int a = 1; a <= cnt; a++)
{
for(auto u: comp2[a])
for(auto v: comp2[a])
if(p[u][v] != 1)
return 0;
for(int b = 1; b < comp2[a].size(); b++)
answer[comp2[a][b]][comp2[a][b - 1]] = answer[comp2[a][b - 1]][comp2[a][b]] = 1;
}
for(int a = 2; a <= cnt; a++)
answer[comp2[a][0]][comp2[a - 1][0]] = answer[comp2[a- 1][0]][comp2[a][0]] = 1;
answer[comp2[1][0]][comp2[cnt][0]] = answer[comp2[cnt][0]][comp2[1][0]] = 1;
for(int a = 1; a <= cnt; a++)
comp2[a].clear();
}
}
build(answer);
// for(int a = 0; a < n; a++)
// for(int b = 0; b < n; b++)
// if(answer[a][b])
// printf("%d %d\n", a, b);
return 1;
}
Compilation message
supertrees.cpp: In function 'bool checkValid()':
supertrees.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int b = 0; b < comp[a].size(); b++)
| ~~^~~~~~~~~~~~~~~~
supertrees.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int c = 0; c < comp[a].size(); c++)
| ~~^~~~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:88:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(int a = 1; a < comp[i].size(); a++)
| ~~^~~~~~~~~~~~~~~~
supertrees.cpp:95:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for(int a = 1; a <= comp[i].size(); a++)
| ~~^~~~~~~~~~~~~~~~~
supertrees.cpp:129:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
129 | for(int b = 1; b < comp2[a].size(); b++)
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
250 ms |
26136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
250 ms |
26136 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
253 ms |
26204 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
123 ms |
16376 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
86 ms |
6904 KB |
Output is correct |
21 |
Correct |
251 ms |
26232 KB |
Output is correct |
22 |
Correct |
238 ms |
26104 KB |
Output is correct |
23 |
Correct |
259 ms |
26104 KB |
Output is correct |
24 |
Correct |
250 ms |
26104 KB |
Output is correct |
25 |
Correct |
111 ms |
16148 KB |
Output is correct |
26 |
Correct |
104 ms |
16172 KB |
Output is correct |
27 |
Correct |
270 ms |
26132 KB |
Output is correct |
28 |
Correct |
244 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
10 ms |
1460 KB |
Output is correct |
9 |
Correct |
288 ms |
26132 KB |
Output is correct |
10 |
Correct |
0 ms |
416 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
11 ms |
1408 KB |
Output is correct |
13 |
Correct |
286 ms |
26132 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
6 ms |
1024 KB |
Output is correct |
17 |
Correct |
111 ms |
16248 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
70 ms |
6904 KB |
Output is correct |
22 |
Correct |
248 ms |
26104 KB |
Output is correct |
23 |
Correct |
263 ms |
26132 KB |
Output is correct |
24 |
Correct |
278 ms |
26236 KB |
Output is correct |
25 |
Correct |
105 ms |
16248 KB |
Output is correct |
26 |
Correct |
110 ms |
16152 KB |
Output is correct |
27 |
Correct |
258 ms |
26136 KB |
Output is correct |
28 |
Correct |
258 ms |
26104 KB |
Output is correct |
29 |
Correct |
111 ms |
16248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
65 ms |
6904 KB |
Output is correct |
5 |
Correct |
243 ms |
26232 KB |
Output is correct |
6 |
Correct |
246 ms |
26212 KB |
Output is correct |
7 |
Correct |
252 ms |
26104 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
60 ms |
6904 KB |
Output is correct |
10 |
Correct |
241 ms |
26104 KB |
Output is correct |
11 |
Correct |
241 ms |
26104 KB |
Output is correct |
12 |
Correct |
250 ms |
26108 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
60 ms |
6904 KB |
Output is correct |
17 |
Correct |
242 ms |
26244 KB |
Output is correct |
18 |
Correct |
242 ms |
26108 KB |
Output is correct |
19 |
Correct |
243 ms |
26104 KB |
Output is correct |
20 |
Correct |
240 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
250 ms |
26136 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
253 ms |
26204 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
123 ms |
16376 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
86 ms |
6904 KB |
Output is correct |
21 |
Correct |
251 ms |
26232 KB |
Output is correct |
22 |
Correct |
238 ms |
26104 KB |
Output is correct |
23 |
Correct |
259 ms |
26104 KB |
Output is correct |
24 |
Correct |
250 ms |
26104 KB |
Output is correct |
25 |
Correct |
111 ms |
16148 KB |
Output is correct |
26 |
Correct |
104 ms |
16172 KB |
Output is correct |
27 |
Correct |
270 ms |
26132 KB |
Output is correct |
28 |
Correct |
244 ms |
26104 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1460 KB |
Output is correct |
37 |
Correct |
288 ms |
26132 KB |
Output is correct |
38 |
Correct |
0 ms |
416 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
286 ms |
26132 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
0 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
111 ms |
16248 KB |
Output is correct |
46 |
Correct |
0 ms |
384 KB |
Output is correct |
47 |
Correct |
0 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
70 ms |
6904 KB |
Output is correct |
50 |
Correct |
248 ms |
26104 KB |
Output is correct |
51 |
Correct |
263 ms |
26132 KB |
Output is correct |
52 |
Correct |
278 ms |
26236 KB |
Output is correct |
53 |
Correct |
105 ms |
16248 KB |
Output is correct |
54 |
Correct |
110 ms |
16152 KB |
Output is correct |
55 |
Correct |
258 ms |
26136 KB |
Output is correct |
56 |
Correct |
258 ms |
26104 KB |
Output is correct |
57 |
Correct |
111 ms |
16248 KB |
Output is correct |
58 |
Correct |
0 ms |
384 KB |
Output is correct |
59 |
Correct |
0 ms |
384 KB |
Output is correct |
60 |
Correct |
5 ms |
1024 KB |
Output is correct |
61 |
Correct |
115 ms |
16272 KB |
Output is correct |
62 |
Correct |
0 ms |
384 KB |
Output is correct |
63 |
Correct |
0 ms |
384 KB |
Output is correct |
64 |
Correct |
0 ms |
384 KB |
Output is correct |
65 |
Correct |
60 ms |
6904 KB |
Output is correct |
66 |
Correct |
101 ms |
16120 KB |
Output is correct |
67 |
Correct |
102 ms |
16120 KB |
Output is correct |
68 |
Correct |
100 ms |
16120 KB |
Output is correct |
69 |
Correct |
105 ms |
16248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
250 ms |
26136 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
10 ms |
1408 KB |
Output is correct |
13 |
Correct |
253 ms |
26204 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
123 ms |
16376 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
86 ms |
6904 KB |
Output is correct |
21 |
Correct |
251 ms |
26232 KB |
Output is correct |
22 |
Correct |
238 ms |
26104 KB |
Output is correct |
23 |
Correct |
259 ms |
26104 KB |
Output is correct |
24 |
Correct |
250 ms |
26104 KB |
Output is correct |
25 |
Correct |
111 ms |
16148 KB |
Output is correct |
26 |
Correct |
104 ms |
16172 KB |
Output is correct |
27 |
Correct |
270 ms |
26132 KB |
Output is correct |
28 |
Correct |
244 ms |
26104 KB |
Output is correct |
29 |
Correct |
0 ms |
384 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
10 ms |
1460 KB |
Output is correct |
37 |
Correct |
288 ms |
26132 KB |
Output is correct |
38 |
Correct |
0 ms |
416 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
11 ms |
1408 KB |
Output is correct |
41 |
Correct |
286 ms |
26132 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
0 ms |
384 KB |
Output is correct |
44 |
Correct |
6 ms |
1024 KB |
Output is correct |
45 |
Correct |
111 ms |
16248 KB |
Output is correct |
46 |
Correct |
0 ms |
384 KB |
Output is correct |
47 |
Correct |
0 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
70 ms |
6904 KB |
Output is correct |
50 |
Correct |
248 ms |
26104 KB |
Output is correct |
51 |
Correct |
263 ms |
26132 KB |
Output is correct |
52 |
Correct |
278 ms |
26236 KB |
Output is correct |
53 |
Correct |
105 ms |
16248 KB |
Output is correct |
54 |
Correct |
110 ms |
16152 KB |
Output is correct |
55 |
Correct |
258 ms |
26136 KB |
Output is correct |
56 |
Correct |
258 ms |
26104 KB |
Output is correct |
57 |
Correct |
111 ms |
16248 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
0 ms |
384 KB |
Output is correct |
60 |
Correct |
0 ms |
384 KB |
Output is correct |
61 |
Correct |
65 ms |
6904 KB |
Output is correct |
62 |
Correct |
243 ms |
26232 KB |
Output is correct |
63 |
Correct |
246 ms |
26212 KB |
Output is correct |
64 |
Correct |
252 ms |
26104 KB |
Output is correct |
65 |
Correct |
0 ms |
384 KB |
Output is correct |
66 |
Correct |
60 ms |
6904 KB |
Output is correct |
67 |
Correct |
241 ms |
26104 KB |
Output is correct |
68 |
Correct |
241 ms |
26104 KB |
Output is correct |
69 |
Correct |
250 ms |
26108 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
512 KB |
Output is correct |
72 |
Correct |
0 ms |
384 KB |
Output is correct |
73 |
Correct |
60 ms |
6904 KB |
Output is correct |
74 |
Correct |
242 ms |
26244 KB |
Output is correct |
75 |
Correct |
242 ms |
26108 KB |
Output is correct |
76 |
Correct |
243 ms |
26104 KB |
Output is correct |
77 |
Correct |
240 ms |
26104 KB |
Output is correct |
78 |
Correct |
0 ms |
384 KB |
Output is correct |
79 |
Correct |
0 ms |
384 KB |
Output is correct |
80 |
Correct |
5 ms |
1024 KB |
Output is correct |
81 |
Correct |
115 ms |
16272 KB |
Output is correct |
82 |
Correct |
0 ms |
384 KB |
Output is correct |
83 |
Correct |
0 ms |
384 KB |
Output is correct |
84 |
Correct |
0 ms |
384 KB |
Output is correct |
85 |
Correct |
60 ms |
6904 KB |
Output is correct |
86 |
Correct |
101 ms |
16120 KB |
Output is correct |
87 |
Correct |
102 ms |
16120 KB |
Output is correct |
88 |
Correct |
100 ms |
16120 KB |
Output is correct |
89 |
Correct |
105 ms |
16248 KB |
Output is correct |
90 |
Correct |
0 ms |
384 KB |
Output is correct |
91 |
Correct |
0 ms |
384 KB |
Output is correct |
92 |
Correct |
7 ms |
1024 KB |
Output is correct |
93 |
Correct |
112 ms |
16276 KB |
Output is correct |
94 |
Correct |
1 ms |
384 KB |
Output is correct |
95 |
Correct |
0 ms |
384 KB |
Output is correct |
96 |
Correct |
0 ms |
384 KB |
Output is correct |
97 |
Correct |
25 ms |
4352 KB |
Output is correct |
98 |
Correct |
106 ms |
16120 KB |
Output is correct |
99 |
Correct |
102 ms |
16240 KB |
Output is correct |
100 |
Correct |
100 ms |
16120 KB |
Output is correct |
101 |
Correct |
103 ms |
16248 KB |
Output is correct |
102 |
Correct |
110 ms |
16248 KB |
Output is correct |
103 |
Correct |
110 ms |
16248 KB |
Output is correct |
104 |
Correct |
108 ms |
16120 KB |
Output is correct |
105 |
Correct |
110 ms |
16248 KB |
Output is correct |