Submission #509769

#TimeUsernameProblemLanguageResultExecution timeMemory
509769KoDHiperkocka (COCI21_hiperkocka)C++17
110 / 110
165 ms43592 KiB
#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 timeMemoryGrader output
Fetching results...