This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "supertrees.h"
using pair = std::array<int, 2>;
using ll = long long;
void stress(std::vector<std::vector<int>> p, std::vector<std::vector<int>> ans) {
int n = p.size();
std::vector<std::vector<int>> hits(n, std::vector<int>(n));
auto adj = hits;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j or ans[i][j] == 0) continue;
adj[i].push_back(j);
adj[j].push_back(i);
}
}
std::function<int(int, int, int)> dfs = [&](int u, int parent, int target) {
if (target == u) return 1;
int res = 0;
for (auto v : adj[u]) {
if (parent == v) continue;
res += dfs(v, u, target);
}
return res;
};
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) hits[i][i] = 1;
else hits[i][j] = dfs(i, -1, j);
if (hits[i][j] != p[i][j]) {
std::cout << "mismatch\n" << i << ' ' << j << " expected " << p[i][j] << " got " << hits[i][j] << '\n';;
}
}
}
std::cout << "stress test ok\n";
}
int construct(std::vector<std::vector<int>> p) {
int n = p.size();
std::vector<std::vector<int>> ans(n, std::vector<int>(n)), lines;
std::vector<int> part(n, -1);
int max = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j || p[i][j] == 0) continue;
if (part[i] > -1 && part[j] > -1) {
if (part[i] != part[j]) return 0;
continue;
}
max = std::max(p[i][j], max);
if (part[i] > -1) lines[part[i]].push_back(j), part[j] = part[i];
else if (part[j] > -1) lines[part[j]].push_back(i), part[i] = part[j];
else {
lines.push_back({});
lines.back().push_back(i);
lines.back().push_back(j);
part[i] = part[j] = lines.size() - 1;
}
}
}
for (auto line : lines) {
if (max == 2 && line.size() == 2) return 0;
for (int i = 0; i < line.size(); i++) {
for (int j = i+1; j < line.size(); j++) {
if (p[line[i]][line[j]] == 0) return 0;
}
// std::cout << line[i] << ' ';
if (max == 2) {
ans[line[i]][line[(i+1)%line.size()]] = ans[line[(i + 1)%line.size()]][line[i]] = 1;
} else {
if (i != line.size() - 1) ans[line[i]][line[(i+1)]] = ans[line[(i + 1)]][line[i]] = 1;
}
} // std::cout << '\n';
}
build(ans);
return 1;
}
Compilation message (stderr)
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:72:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int i = 0; i < line.size(); i++) {
| ~~^~~~~~~~~~~~~
supertrees.cpp:73:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for (int j = i+1; j < line.size(); j++) {
| ~~^~~~~~~~~~~~~
supertrees.cpp:80:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | if (i != line.size() - 1) ans[line[i]][line[(i+1)]] = ans[line[(i + 1)]][line[i]] = 1;
| ~~^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |