# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
509769 | KoD | Hiperkocka (COCI21_hiperkocka) | C++17 | 165 ms | 43592 KiB |
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>
using std::vector;
using std::array;
using std::pair;
using std::tuple;
vector<std::map<int, int>> build(vector<pair<int, int>> edge) {
const int n = edge.size();
if (n == 1) {
std::map<int, int> ret;
const auto& [x, y] = edge[0];
ret[x] = 0;
ret[y] = 1;
return {ret};
}
std::map<int, int> deg;
for (const auto& [x, y] : edge) {
deg[x] += 1;
deg[y] += 1;
}
for (int i = 0; i < n; ++i) {
auto& [x, y] = edge[i];
if (deg[y] == 1) std::swap(x, y);
if (deg[x] == 1) {
std::swap(edge[i], edge[n - 1]);
break;
}
}
const auto [cut, other] = edge[n - 1];
edge.pop_back();
vector<std::map<int, int>> ret;
auto smaller = build(edge);
for (const auto& v : smaller) {
{
auto& add = ret.emplace_back(v);
for (auto& [x, y] : add) {
y <<= 1;
}
add[cut] = add[other] ^ 1;
}
{
auto& add = ret.emplace_back(v);
for (auto& [x, y] : add) {
y = ((y ^ 1) << 1) ^ 1;
}
add[cut] = add[other] ^ 1;
}
}
return ret;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
std::cin >> N;
vector<pair<int, int>> edge(N);
for (auto& [x, y] : edge) {
std::cin >> x >> y;
}
auto ans = build(edge);
std::cout << (1 << (N - 1)) << '\n';
for (auto& v : ans) {
for (int i = 0; i <= N; ++i) {
std::cout << v[i] << " \n"[i == N];
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |