#include "supertrees.h"
#ifdef ngu
#include "grader.cpp"
#endif // ngu
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
auto valid = [&] (vector<int> a, vector<int> b, int c) {
for(int &j : a) for(int &k : b) if (p[j][k] != c) return false;
return true;
};
vector<int> vis(n), arr;
auto dfs = [&] (auto self, int u) -> void {
vis[u] = 1;
arr.push_back(u);
for(int v = 0; v < n; v++) if (!vis[v] && p[u][v] == 1) self(self, v);
};
std::vector<std::vector<int>> answer(n, vector<int> (n));
auto add = [&] (int u, int v) {
answer[u][v] = answer[v][u] = 1;
};
vector<vector<int> > connected;
for(int i = 0; i < n; i++) if (!vis[i]) {
arr.clear();
dfs(dfs, i);
if (!valid(arr, arr, 1)) return 0;
connected.push_back(arr);
for(int j = 1; j < arr.size(); j++) {
answer[arr[j]][arr[j - 1]] = answer[arr[j - 1]][arr[j]] = 1;
}
}
for(int i = 0; i < n; i++) vis[i] = 0;
for(auto &arr : connected) {
for(auto &j : arr) for(int k = 0; k < n; k++) if (p[j][k] != p[arr[0]][k]) return 0;
}
// auto _dfs = [&] (auto self, int u) -> void {
// vis[u] = 1;
// arr.push_back(u);
// for(int v = 0; v < n; v++) if (!vis[v] && p[u][v] == 1) self(self, v);
// };
auto _dfs = [&] (auto self, int u) -> void {
vis[u] = 1;
arr.push_back(u);
for(int v = 0; v < connected.size(); v++) if (!vis[v] && p[connected[u][0]][connected[v][0]] == 2) {
self(self, v);
}
};
for(int i = 0; i < connected.size(); i++) if (!vis[i]) {
arr.clear();
for(int &k : arr) for(int &j : arr) if (j != k) {
if (p[connected[k][0]][connected[j][0]] != 2) return 0;
}
_dfs(_dfs, i);
if (arr.size() == 1) continue;
if (arr.size() < 3) return 0;
// for(int &j : g) cout << j << " "; cout << endl;
for(int i = 1; i < arr.size(); i++) {
add(connected[arr[i]][0], connected[arr[i - 1]][0]);
}
add(connected[arr[0]][0], connected[arr.back()][0]);
}
build(answer);
for(int i = 0; i < n; i++) {
auto expand = [&] (int u) {
};
}
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:39:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int j = 1; j < arr.size(); j++) {
| ~~^~~~~~~~~~~~
supertrees.cpp:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 0; i < connected.size(); i++) if (!vis[i]) {
| ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int i = 1; i < arr.size(); i++) {
| ~~^~~~~~~~~~~~
supertrees.cpp:82:10: warning: variable 'expand' set but not used [-Wunused-but-set-variable]
82 | auto expand = [&] (int u) {
| ^~~~~~
supertrees.cpp: In instantiation of 'construct(std::vector<std::vector<int> >)::<lambda(auto:24, int)> [with auto:24 = construct(std::vector<std::vector<int> >)::<lambda(auto:24, int)>]':
supertrees.cpp:69:17: required from here
supertrees.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int v = 0; v < connected.size(); v++) if (!vis[v] && p[connected[u][0]][connected[v][0]] == 2) {
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1368 KB |
Output is correct |
7 |
Correct |
153 ms |
24064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1368 KB |
Output is correct |
7 |
Correct |
153 ms |
24064 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1184 KB |
Output is correct |
13 |
Correct |
154 ms |
24048 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
932 KB |
Output is correct |
17 |
Correct |
67 ms |
14252 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
44 ms |
6340 KB |
Output is correct |
21 |
Correct |
166 ms |
24080 KB |
Output is correct |
22 |
Correct |
160 ms |
24036 KB |
Output is correct |
23 |
Correct |
169 ms |
23976 KB |
Output is correct |
24 |
Correct |
155 ms |
23940 KB |
Output is correct |
25 |
Correct |
65 ms |
14160 KB |
Output is correct |
26 |
Correct |
64 ms |
14160 KB |
Output is correct |
27 |
Correct |
155 ms |
24148 KB |
Output is correct |
28 |
Correct |
153 ms |
24192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
7 ms |
1372 KB |
Output is correct |
9 |
Correct |
152 ms |
24076 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
9 ms |
1416 KB |
Output is correct |
13 |
Correct |
154 ms |
24144 KB |
Output is correct |
14 |
Incorrect |
1 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
39 ms |
6196 KB |
Output is correct |
5 |
Correct |
157 ms |
24052 KB |
Output is correct |
6 |
Correct |
157 ms |
24348 KB |
Output is correct |
7 |
Correct |
159 ms |
23924 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
40 ms |
6420 KB |
Output is correct |
10 |
Correct |
155 ms |
24064 KB |
Output is correct |
11 |
Correct |
160 ms |
24148 KB |
Output is correct |
12 |
Correct |
162 ms |
24200 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
40 ms |
6388 KB |
Output is correct |
17 |
Correct |
163 ms |
22748 KB |
Output is correct |
18 |
Correct |
153 ms |
24148 KB |
Output is correct |
19 |
Correct |
155 ms |
23472 KB |
Output is correct |
20 |
Correct |
156 ms |
23724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1368 KB |
Output is correct |
7 |
Correct |
153 ms |
24064 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1184 KB |
Output is correct |
13 |
Correct |
154 ms |
24048 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
932 KB |
Output is correct |
17 |
Correct |
67 ms |
14252 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
44 ms |
6340 KB |
Output is correct |
21 |
Correct |
166 ms |
24080 KB |
Output is correct |
22 |
Correct |
160 ms |
24036 KB |
Output is correct |
23 |
Correct |
169 ms |
23976 KB |
Output is correct |
24 |
Correct |
155 ms |
23940 KB |
Output is correct |
25 |
Correct |
65 ms |
14160 KB |
Output is correct |
26 |
Correct |
64 ms |
14160 KB |
Output is correct |
27 |
Correct |
155 ms |
24148 KB |
Output is correct |
28 |
Correct |
153 ms |
24192 KB |
Output is correct |
29 |
Correct |
1 ms |
504 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
7 ms |
1372 KB |
Output is correct |
37 |
Correct |
152 ms |
24076 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
9 ms |
1416 KB |
Output is correct |
41 |
Correct |
154 ms |
24144 KB |
Output is correct |
42 |
Incorrect |
1 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
7 ms |
1368 KB |
Output is correct |
7 |
Correct |
153 ms |
24064 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
7 ms |
1184 KB |
Output is correct |
13 |
Correct |
154 ms |
24048 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
932 KB |
Output is correct |
17 |
Correct |
67 ms |
14252 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
44 ms |
6340 KB |
Output is correct |
21 |
Correct |
166 ms |
24080 KB |
Output is correct |
22 |
Correct |
160 ms |
24036 KB |
Output is correct |
23 |
Correct |
169 ms |
23976 KB |
Output is correct |
24 |
Correct |
155 ms |
23940 KB |
Output is correct |
25 |
Correct |
65 ms |
14160 KB |
Output is correct |
26 |
Correct |
64 ms |
14160 KB |
Output is correct |
27 |
Correct |
155 ms |
24148 KB |
Output is correct |
28 |
Correct |
153 ms |
24192 KB |
Output is correct |
29 |
Correct |
1 ms |
504 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
7 ms |
1372 KB |
Output is correct |
37 |
Correct |
152 ms |
24076 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
9 ms |
1416 KB |
Output is correct |
41 |
Correct |
154 ms |
24144 KB |
Output is correct |
42 |
Incorrect |
1 ms |
348 KB |
Answer gives possible 1 while actual possible 0 |
43 |
Halted |
0 ms |
0 KB |
- |