#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
struct DSU {
vector<int> nodes;
int find(int node) {
if (nodes[node] < 0) return node;
return nodes[node] = find(nodes[node]);
}
void join(int u, int v) {
u = find(u), v = find(v);
if (u == v) return;
if (nodes[u] > nodes[v]) swap(u, v);
nodes[u] += nodes[v];
nodes[v] = u;
}
map<int, vector<int>> get_cc() {
map<int, vector<int>> ans;
for (int i = 0; i < nodes.size(); i++) {
ans[find(i)].push_back(i);
}
return ans;
}
DSU(int size) : nodes(size, -1) { }
};
int construct(vector<vector<int>> p) {
int n = p.size();
vector adj(n, vector(n, 0));
DSU dsu(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i][j]) dsu.join(i, j);
}
}
auto ccs = dsu.get_cc();
for (auto [_, cc]: ccs) {
DSU dsu2(cc.size());
for (int i = 0; i < cc.size(); i++) {
for (int j = 0; j < cc.size(); j++) {
if (p[cc[i]][cc[j]] == 1) dsu2.join(i, j);
}
}
auto ccs2 = dsu2.get_cc();
vector<int> cycle;
for (auto [r, cc2]: ccs2) {
cycle.push_back(cc[r]);
for (int i = 1; i < cc2.size(); i++) {
adj[cc[cc2[i]]][cc[cc2[i - 1]]] = adj[cc[cc2[i - 1]]][cc[cc2[i]]] = 1;
}
}
if (cycle.size() < 3) continue;
for (int i = 0; i < cycle.size(); i++) {
adj[cycle[i]][cycle[(i + 1) % cycle.size()]] = adj[cycle[(i + 1) % cycle.size()]][cycle[i]] = 1;
}
}
build(adj);
return 1;
}
Compilation message
supertrees.cpp: In member function 'std::map<int, std::vector<int> > DSU::get_cc()':
supertrees.cpp:24:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int i = 0; i < nodes.size(); i++) {
| ~~^~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < cc.size(); i++) {
| ~~^~~~~~~~~~~
supertrees.cpp:48:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int j = 0; j < cc.size(); j++) {
| ~~^~~~~~~~~~~
supertrees.cpp:56:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int i = 1; i < cc2.size(); i++) {
| ~~^~~~~~~~~~~~
supertrees.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for (int i = 0; i < cycle.size(); i++) {
| ~~^~~~~~~~~~~~~~
# |
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 |
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 |
6 ms |
1268 KB |
Output is correct |
7 |
Correct |
151 ms |
23932 KB |
Output is correct |
# |
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 |
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 |
6 ms |
1268 KB |
Output is correct |
7 |
Correct |
151 ms |
23932 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 |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
8 ms |
1176 KB |
Output is correct |
13 |
Correct |
148 ms |
23828 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
15 |
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 |
Incorrect |
1 ms |
300 KB |
Answer gives possible 1 while actual possible 0 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
37 ms |
6216 KB |
Output is correct |
5 |
Correct |
144 ms |
23924 KB |
Output is correct |
6 |
Correct |
147 ms |
24012 KB |
Output is correct |
7 |
Correct |
152 ms |
23932 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
37 ms |
6252 KB |
Output is correct |
10 |
Correct |
147 ms |
24016 KB |
Output is correct |
11 |
Correct |
144 ms |
23924 KB |
Output is correct |
12 |
Correct |
170 ms |
23920 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
40 ms |
6156 KB |
Output is correct |
17 |
Correct |
149 ms |
23984 KB |
Output is correct |
18 |
Correct |
162 ms |
24012 KB |
Output is correct |
19 |
Correct |
145 ms |
23968 KB |
Output is correct |
20 |
Correct |
144 ms |
24028 KB |
Output is correct |
# |
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 |
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 |
6 ms |
1268 KB |
Output is correct |
7 |
Correct |
151 ms |
23932 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 |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
8 ms |
1176 KB |
Output is correct |
13 |
Correct |
148 ms |
23828 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 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 |
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 |
6 ms |
1268 KB |
Output is correct |
7 |
Correct |
151 ms |
23932 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 |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
8 ms |
1176 KB |
Output is correct |
13 |
Correct |
148 ms |
23828 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Answer gives possible 1 while actual possible 0 |
15 |
Halted |
0 ms |
0 KB |
- |