#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#include "supertrees.h"
#include <vector>
void build(vector<vector<int>> b);
const int N = 1005;
int n, mx, vis[N];
vector<int> block, edge, circle;
vector<vector<int>> path, ans;
void st(int u, int v) {
ans[u][v] = 1; ans[v][u] = 1;
}
void dfs(int u) {
vis[u] = 1;
block.push_back(u);
for (int v = 0; v < n; v++) {
mx = max(mx, path[u][v]);
if (!vis[v] && path[u][v]) dfs(v);
}
}
void find_cycle(int u) {
vis[u] = 2;
edge.push_back(u);
for (int v = 0; v < n; v++) {
if (vis[v] == 1 && path[u][v] == 1) find_cycle(v);
}
}
int construct(std::vector<std::vector<int>> p) {
path = p; n = p.size(); ans.resize(n);
for (int i = 0; i < n; i++) ans[i].resize(n);
for (int i = 0; i < n; i++) {
if (vis[i]) continue;
mx = 1; block.clear(); dfs(i);
if (mx == 3) return 0;
int sz = block.size();
for (int f = 1; f < sz; f++) {
for (int k = 0; k < f; k++) {
if (!path[block[f]][block[k]]) return 0;
}
}
if (mx == 1) {
for(int j=1;j<sz;j++)st(block[0], block[j]);
}
else {
circle.clear();
for (int j = 0, k = block[j]; j < sz; j++, k = block[j]) {
if (vis[k] != 1) continue;
edge.clear();
find_cycle(k);
for (int a = 1; a < edge.size(); a++) {
for (int b = 0; b < a; b++) {
if (path[edge[a]][edge[b]] != 1) return 0;
}
st(edge[0], edge[a]);
}
circle.push_back(edge[0]);
}
if (circle.size() <= 2) return 0;
int sz3 = circle.size();
for (int j = 0; j < sz3; j++) st(circle[j], circle[(j + 1) % sz3]);
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int a = 1; a < edge.size(); a++) {
| ~~^~~~~~~~~~~~~
# |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1408 KB |
Output is correct |
7 |
Correct |
183 ms |
27916 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1408 KB |
Output is correct |
7 |
Correct |
183 ms |
27916 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1364 KB |
Output is correct |
13 |
Correct |
176 ms |
27948 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 |
980 KB |
Output is correct |
17 |
Correct |
108 ms |
18100 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
42 ms |
7244 KB |
Output is correct |
21 |
Correct |
171 ms |
27904 KB |
Output is correct |
22 |
Correct |
169 ms |
27904 KB |
Output is correct |
23 |
Correct |
191 ms |
27896 KB |
Output is correct |
24 |
Correct |
190 ms |
27900 KB |
Output is correct |
25 |
Correct |
73 ms |
18004 KB |
Output is correct |
26 |
Correct |
73 ms |
18040 KB |
Output is correct |
27 |
Correct |
184 ms |
27896 KB |
Output is correct |
28 |
Correct |
170 ms |
28028 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 |
Correct |
1 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 |
300 KB |
Output is correct |
8 |
Correct |
8 ms |
1428 KB |
Output is correct |
9 |
Correct |
175 ms |
27952 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1364 KB |
Output is correct |
13 |
Correct |
178 ms |
27976 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
6 ms |
980 KB |
Output is correct |
17 |
Correct |
89 ms |
17996 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
55 ms |
7156 KB |
Output is correct |
22 |
Correct |
172 ms |
27900 KB |
Output is correct |
23 |
Correct |
193 ms |
27900 KB |
Output is correct |
24 |
Correct |
215 ms |
27908 KB |
Output is correct |
25 |
Correct |
79 ms |
17988 KB |
Output is correct |
26 |
Correct |
73 ms |
18056 KB |
Output is correct |
27 |
Correct |
182 ms |
27896 KB |
Output is correct |
28 |
Correct |
186 ms |
27980 KB |
Output is correct |
29 |
Correct |
73 ms |
18044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
43 ms |
7220 KB |
Output is correct |
5 |
Correct |
171 ms |
27964 KB |
Output is correct |
6 |
Correct |
190 ms |
27948 KB |
Output is correct |
7 |
Correct |
218 ms |
27912 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
47 ms |
7272 KB |
Output is correct |
10 |
Correct |
199 ms |
27904 KB |
Output is correct |
11 |
Correct |
175 ms |
27852 KB |
Output is correct |
12 |
Correct |
215 ms |
27980 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
46 ms |
7168 KB |
Output is correct |
17 |
Correct |
183 ms |
27892 KB |
Output is correct |
18 |
Correct |
192 ms |
27852 KB |
Output is correct |
19 |
Correct |
185 ms |
27900 KB |
Output is correct |
20 |
Correct |
176 ms |
27896 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1408 KB |
Output is correct |
7 |
Correct |
183 ms |
27916 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1364 KB |
Output is correct |
13 |
Correct |
176 ms |
27948 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 |
980 KB |
Output is correct |
17 |
Correct |
108 ms |
18100 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
42 ms |
7244 KB |
Output is correct |
21 |
Correct |
171 ms |
27904 KB |
Output is correct |
22 |
Correct |
169 ms |
27904 KB |
Output is correct |
23 |
Correct |
191 ms |
27896 KB |
Output is correct |
24 |
Correct |
190 ms |
27900 KB |
Output is correct |
25 |
Correct |
73 ms |
18004 KB |
Output is correct |
26 |
Correct |
73 ms |
18040 KB |
Output is correct |
27 |
Correct |
184 ms |
27896 KB |
Output is correct |
28 |
Correct |
170 ms |
28028 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 |
Correct |
1 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 |
300 KB |
Output is correct |
36 |
Correct |
8 ms |
1428 KB |
Output is correct |
37 |
Correct |
175 ms |
27952 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1364 KB |
Output is correct |
41 |
Correct |
178 ms |
27976 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
308 KB |
Output is correct |
44 |
Correct |
6 ms |
980 KB |
Output is correct |
45 |
Correct |
89 ms |
17996 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
55 ms |
7156 KB |
Output is correct |
50 |
Correct |
172 ms |
27900 KB |
Output is correct |
51 |
Correct |
193 ms |
27900 KB |
Output is correct |
52 |
Correct |
215 ms |
27908 KB |
Output is correct |
53 |
Correct |
79 ms |
17988 KB |
Output is correct |
54 |
Correct |
73 ms |
18056 KB |
Output is correct |
55 |
Correct |
182 ms |
27896 KB |
Output is correct |
56 |
Correct |
186 ms |
27980 KB |
Output is correct |
57 |
Correct |
73 ms |
18044 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 |
980 KB |
Output is correct |
61 |
Correct |
105 ms |
18096 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
304 KB |
Output is correct |
64 |
Correct |
1 ms |
212 KB |
Output is correct |
65 |
Correct |
47 ms |
7184 KB |
Output is correct |
66 |
Correct |
77 ms |
17996 KB |
Output is correct |
67 |
Correct |
74 ms |
18040 KB |
Output is correct |
68 |
Correct |
71 ms |
17964 KB |
Output is correct |
69 |
Correct |
75 ms |
17968 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1408 KB |
Output is correct |
7 |
Correct |
183 ms |
27916 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
8 ms |
1364 KB |
Output is correct |
13 |
Correct |
176 ms |
27948 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 |
980 KB |
Output is correct |
17 |
Correct |
108 ms |
18100 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
42 ms |
7244 KB |
Output is correct |
21 |
Correct |
171 ms |
27904 KB |
Output is correct |
22 |
Correct |
169 ms |
27904 KB |
Output is correct |
23 |
Correct |
191 ms |
27896 KB |
Output is correct |
24 |
Correct |
190 ms |
27900 KB |
Output is correct |
25 |
Correct |
73 ms |
18004 KB |
Output is correct |
26 |
Correct |
73 ms |
18040 KB |
Output is correct |
27 |
Correct |
184 ms |
27896 KB |
Output is correct |
28 |
Correct |
170 ms |
28028 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 |
Correct |
1 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 |
300 KB |
Output is correct |
36 |
Correct |
8 ms |
1428 KB |
Output is correct |
37 |
Correct |
175 ms |
27952 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
8 ms |
1364 KB |
Output is correct |
41 |
Correct |
178 ms |
27976 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
308 KB |
Output is correct |
44 |
Correct |
6 ms |
980 KB |
Output is correct |
45 |
Correct |
89 ms |
17996 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
55 ms |
7156 KB |
Output is correct |
50 |
Correct |
172 ms |
27900 KB |
Output is correct |
51 |
Correct |
193 ms |
27900 KB |
Output is correct |
52 |
Correct |
215 ms |
27908 KB |
Output is correct |
53 |
Correct |
79 ms |
17988 KB |
Output is correct |
54 |
Correct |
73 ms |
18056 KB |
Output is correct |
55 |
Correct |
182 ms |
27896 KB |
Output is correct |
56 |
Correct |
186 ms |
27980 KB |
Output is correct |
57 |
Correct |
73 ms |
18044 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
308 KB |
Output is correct |
60 |
Correct |
1 ms |
304 KB |
Output is correct |
61 |
Correct |
43 ms |
7220 KB |
Output is correct |
62 |
Correct |
171 ms |
27964 KB |
Output is correct |
63 |
Correct |
190 ms |
27948 KB |
Output is correct |
64 |
Correct |
218 ms |
27912 KB |
Output is correct |
65 |
Correct |
1 ms |
212 KB |
Output is correct |
66 |
Correct |
47 ms |
7272 KB |
Output is correct |
67 |
Correct |
199 ms |
27904 KB |
Output is correct |
68 |
Correct |
175 ms |
27852 KB |
Output is correct |
69 |
Correct |
215 ms |
27980 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
46 ms |
7168 KB |
Output is correct |
74 |
Correct |
183 ms |
27892 KB |
Output is correct |
75 |
Correct |
192 ms |
27852 KB |
Output is correct |
76 |
Correct |
185 ms |
27900 KB |
Output is correct |
77 |
Correct |
176 ms |
27896 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 |
980 KB |
Output is correct |
81 |
Correct |
105 ms |
18096 KB |
Output is correct |
82 |
Correct |
1 ms |
212 KB |
Output is correct |
83 |
Correct |
1 ms |
304 KB |
Output is correct |
84 |
Correct |
1 ms |
212 KB |
Output is correct |
85 |
Correct |
47 ms |
7184 KB |
Output is correct |
86 |
Correct |
77 ms |
17996 KB |
Output is correct |
87 |
Correct |
74 ms |
18040 KB |
Output is correct |
88 |
Correct |
71 ms |
17964 KB |
Output is correct |
89 |
Correct |
75 ms |
17968 KB |
Output is correct |
90 |
Correct |
1 ms |
212 KB |
Output is correct |
91 |
Correct |
0 ms |
212 KB |
Output is correct |
92 |
Correct |
4 ms |
980 KB |
Output is correct |
93 |
Correct |
80 ms |
18112 KB |
Output is correct |
94 |
Correct |
1 ms |
212 KB |
Output is correct |
95 |
Correct |
1 ms |
340 KB |
Output is correct |
96 |
Correct |
1 ms |
212 KB |
Output is correct |
97 |
Correct |
19 ms |
4660 KB |
Output is correct |
98 |
Correct |
75 ms |
17968 KB |
Output is correct |
99 |
Correct |
80 ms |
18048 KB |
Output is correct |
100 |
Correct |
80 ms |
18048 KB |
Output is correct |
101 |
Correct |
80 ms |
17952 KB |
Output is correct |
102 |
Correct |
74 ms |
18096 KB |
Output is correct |
103 |
Correct |
74 ms |
18096 KB |
Output is correct |
104 |
Correct |
79 ms |
18172 KB |
Output is correct |
105 |
Correct |
82 ms |
18044 KB |
Output is correct |