#include <cstdio> #include <cstdlib> #include <cstdint> #include <vector> #include <utility> #include <numeric> std::vector<bool> solve1(std::vector<std::pair<int, int>> commands, const uint64_t n) { std::vector<bool> ret(n, false); for (uint64_t starts = 1; starts < 1ULL << n; starts++) { uint64_t s = starts; for (const auto [a, b] : commands) { const uint64_t mask = (1ULL << a) | (1ULL << b); if ((s & mask) == (1ULL << a)) { s ^= mask; } } const int k = std::popcount(s); const int i = std::countr_zero(s); if (s == ((1ULL << k) - 1) << i) { ret[k - 1] = !ret[k - 1]; } } return ret; } int main() { int n, m; scanf("%d %d", &n, &m); std::vector<std::pair<int, int>> commands; commands.reserve(m); for (int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); commands.push_back({a - 1, b - 1}); } auto result = solve1(std::move(commands), n); bool first = true; for (bool b : result) { if (first) { first = false; } else { putchar(' '); } putchar(b ? '1' : '0'); } putchar('\n'); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #include <cstdio> #include <cstdlib> #include <cstdint> #include <vector> #include <utility> #include <numeric> std::vector<bool> solve1(std::vector<std::pair<int, int>> commands, const uint64_t n) { std::vector<bool> ret(n, false); for (uint64_t starts = 1; starts < 1ULL << n; starts++) { uint64_t s = starts; for (const auto [a, b] : commands) { const uint64_t mask = (1ULL << a) | (1ULL << b); if ((s & mask) == (1ULL << a)) { s ^= mask; } } const int k = std::popcount(s); const int i = std::countr_zero(s); if (s == ((1ULL << k) - 1) << i) { ret[k - 1] = !ret[k - 1]; } } return ret; } int main() { int n, m; scanf("%d %d", &n, &m); std::vector<std::pair<int, int>> commands; commands.reserve(m); for (int i = 0; i < m; i++) { int a, b; scanf("%d %d", &a, &b); commands.push_back({a - 1, b - 1}); } auto result = solve1(std::move(commands), n); bool first = true; for (bool b : result) { if (first) { first = false; } else { putchar(' '); } putchar(b ? '1' : '0'); } putchar('\n'); return 0; } |