#include <iostream> #include <vector> using namespace std; using LL = long long; using PII = pair<int, int>; vector<int> solve(int n, int m, const vector<PII>& moves) { vector<int> res(n + 1); for (int i = 0; i < (1L << n); ++i) { int cur = i; for (int j = 0; j < m; ++j) { if (cur & (1 << moves[j].first)) { if (!(cur & (1 << moves[j].second))) { cur ^= (1 << moves[j].first); cur ^= (1 << moves[j].second); } } } int one_min = -1; int one_max = -1; for (int i = 0; i < n; ++i) { if (cur & (1 << i)) { one_min = i; break; } } for (int i = n - 1; i >= 0; --i) { if (cur & (1 << i)) { one_max = i; break; } } if (one_min != -1 && one_max != -1) { bool ok = true; for (int i = one_min + 1; i < one_max; ++i) { if (!(cur & (1 << i))) { ok = false; break; } } if (ok) res[one_max - one_min + 1] ^= 1; } } return res; } int main() { int n, m, a, b; cin >> n >> m; vector<PII> moves(m); for (int i = 0; i < m; ++i) { cin >> a >> b; moves[i] = { a - 1, b - 1 }; } vector<int> res = solve(n, m, moves); for (int i = 1; i <= n; ++i) { cout << (i == 1 ? "" : " ") << res[i]; } 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | #include <iostream> #include <vector> using namespace std; using LL = long long; using PII = pair<int, int>; vector<int> solve(int n, int m, const vector<PII>& moves) { vector<int> res(n + 1); for (int i = 0; i < (1L << n); ++i) { int cur = i; for (int j = 0; j < m; ++j) { if (cur & (1 << moves[j].first)) { if (!(cur & (1 << moves[j].second))) { cur ^= (1 << moves[j].first); cur ^= (1 << moves[j].second); } } } int one_min = -1; int one_max = -1; for (int i = 0; i < n; ++i) { if (cur & (1 << i)) { one_min = i; break; } } for (int i = n - 1; i >= 0; --i) { if (cur & (1 << i)) { one_max = i; break; } } if (one_min != -1 && one_max != -1) { bool ok = true; for (int i = one_min + 1; i < one_max; ++i) { if (!(cur & (1 << i))) { ok = false; break; } } if (ok) res[one_max - one_min + 1] ^= 1; } } return res; } int main() { int n, m, a, b; cin >> n >> m; vector<PII> moves(m); for (int i = 0; i < m; ++i) { cin >> a >> b; moves[i] = { a - 1, b - 1 }; } vector<int> res = solve(n, m, moves); for (int i = 1; i <= n; ++i) { cout << (i == 1 ? "" : " ") << res[i]; } return 0; } |