#include "bits/stdc++.h"
#ifdef sunnatov
#include "grader.cpp"
#else
#include "supertrees.h"
#endif
using namespace std;
struct dsu {
vector<int> p, size;
void init(int n) {
p.assign(n, 0);
size.assign(n, 1);
for (int i = 0; i < n; i++) p[i] = i;
}
int get(int a) {
return p[a] == a ? a : p[a] = get(p[a]);
}
void add(int a, int b) {
a = get(a);
b = get(b);
if (a == b) return;
if (size[a] > size[b]) swap(a, b);
size[b] += size[a];
p[a] = b;
}
};
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
vector<vector<int>> g(n, vector<int>(n));
dsu ds;
ds.init(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j] == 2) {
ds.add(i, j);
}
}
}
vector<bool> vis(n);
for (int _ = 0; _ < n; _++) {
int s = -1;
vector<int> v;
for (int i = 0; i < n; i++) {
if (vis[i]) continue;
if (s == -1) s = ds.get(i);
if (ds.get(i) != s) continue;
v.emplace_back(i);
}
if (v.empty()) break;
for (int i = 0; i < v.size(); i++) {
for (int j = i + 1; j < v.size(); j++) {
if (!p[v[i]][v[j]]) return 0;
}
}
// something
vector<bool> another_vis(n);
vector<int> cycle;
for (int x: v) {
if (another_vis[x]) continue;
vector<int> line;
for (int i = 0; i < n; i++) {
if (p[x][i] == 1) line.emplace_back(i);
}
for (int i = 0; i < line.size(); i++) {
for (int j = i + 1; j < line.size(); j++) {
if (p[line[i]][line[j]] != 1) return 0;
}
}
for (int i = 1; i < line.size(); i++) g[line[i - 1]][line[i]] = g[line[i]][line[i - 1]] = 1;
for (int y: line) another_vis[y] = true;
cycle.emplace_back(line[0]);
}
if (cycle.size() > 2) {
for (int i = 1; i < cycle.size(); i++) g[cycle[i - 1]][cycle[i]] = g[cycle[i]][cycle[i - 1]] = 1;
g[cycle[0]][cycle.back()] = g[cycle.back()][cycle[0]] = 1;
}
for (int x: v) vis[x] = true;
}
build(g);
return 1;
}
Compilation message
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:58:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
supertrees.cpp:59:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for (int j = i + 1; j < v.size(); j++) {
| ~~^~~~~~~~~~
supertrees.cpp:73:31: 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 = 0; i < line.size(); i++) {
| ~~^~~~~~~~~~~~~
supertrees.cpp:74:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for (int j = i + 1; j < line.size(); j++) {
| ~~^~~~~~~~~~~~~
supertrees.cpp:78:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int i = 1; i < line.size(); i++) g[line[i - 1]][line[i]] = g[line[i]][line[i - 1]] = 1;
| ~~^~~~~~~~~~~~~
supertrees.cpp:83:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for (int i = 1; i < cycle.size(); i++) g[cycle[i - 1]][cycle[i]] = g[cycle[i]][cycle[i - 1]] = 1;
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1188 KB |
Output is correct |
7 |
Correct |
410 ms |
22052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1188 KB |
Output is correct |
7 |
Correct |
410 ms |
22052 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
165 ms |
21948 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
67 ms |
12856 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
1 ms |
224 KB |
Output is correct |
20 |
Correct |
40 ms |
6152 KB |
Output is correct |
21 |
Correct |
167 ms |
22812 KB |
Output is correct |
22 |
Correct |
162 ms |
22816 KB |
Output is correct |
23 |
Correct |
253 ms |
22884 KB |
Output is correct |
24 |
Correct |
162 ms |
22724 KB |
Output is correct |
25 |
Correct |
74 ms |
12872 KB |
Output is correct |
26 |
Correct |
70 ms |
12836 KB |
Output is correct |
27 |
Correct |
262 ms |
22748 KB |
Output is correct |
28 |
Correct |
160 ms |
22760 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 |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
1 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 |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
40 ms |
5732 KB |
Output is correct |
5 |
Correct |
167 ms |
22084 KB |
Output is correct |
6 |
Correct |
159 ms |
22044 KB |
Output is correct |
7 |
Correct |
243 ms |
21940 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
43 ms |
5708 KB |
Output is correct |
10 |
Correct |
155 ms |
22048 KB |
Output is correct |
11 |
Correct |
180 ms |
21972 KB |
Output is correct |
12 |
Correct |
160 ms |
22032 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
40 ms |
5716 KB |
Output is correct |
17 |
Correct |
158 ms |
22024 KB |
Output is correct |
18 |
Correct |
168 ms |
22016 KB |
Output is correct |
19 |
Correct |
163 ms |
22020 KB |
Output is correct |
20 |
Correct |
179 ms |
22016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1188 KB |
Output is correct |
7 |
Correct |
410 ms |
22052 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
165 ms |
21948 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
67 ms |
12856 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
1 ms |
224 KB |
Output is correct |
20 |
Correct |
40 ms |
6152 KB |
Output is correct |
21 |
Correct |
167 ms |
22812 KB |
Output is correct |
22 |
Correct |
162 ms |
22816 KB |
Output is correct |
23 |
Correct |
253 ms |
22884 KB |
Output is correct |
24 |
Correct |
162 ms |
22724 KB |
Output is correct |
25 |
Correct |
74 ms |
12872 KB |
Output is correct |
26 |
Correct |
70 ms |
12836 KB |
Output is correct |
27 |
Correct |
262 ms |
22748 KB |
Output is correct |
28 |
Correct |
160 ms |
22760 KB |
Output is correct |
29 |
Correct |
1 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 |
Incorrect |
1 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 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1188 KB |
Output is correct |
7 |
Correct |
410 ms |
22052 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
165 ms |
21948 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
67 ms |
12856 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
1 ms |
224 KB |
Output is correct |
20 |
Correct |
40 ms |
6152 KB |
Output is correct |
21 |
Correct |
167 ms |
22812 KB |
Output is correct |
22 |
Correct |
162 ms |
22816 KB |
Output is correct |
23 |
Correct |
253 ms |
22884 KB |
Output is correct |
24 |
Correct |
162 ms |
22724 KB |
Output is correct |
25 |
Correct |
74 ms |
12872 KB |
Output is correct |
26 |
Correct |
70 ms |
12836 KB |
Output is correct |
27 |
Correct |
262 ms |
22748 KB |
Output is correct |
28 |
Correct |
160 ms |
22760 KB |
Output is correct |
29 |
Correct |
1 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 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
33 |
Halted |
0 ms |
0 KB |
- |