#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif #define x first #define y second #define ir(a, x, b) ((a) <= (x) && (x) <= (b)) #define vec vector #define rep(i, a, b) for (int i = a; i < (b); ++i) #define all(x) (x).begin(), (x).end() #define sz(x) (ll)(x).size() using ll = long long; int N, M; int solve(const int K, const vec<pair<int, int>>& ms) { set<ll> states; ll init = (1ll << K)-1; rep (i, K, N+1) { states.insert(init); init <<= 1; } // debug(states); vec<ll> add, rem; rep (i, 0, sz(ms)) { debug(i); auto [a, b] = ms[i]; for (auto x : states) { ll aon = (x & (1ll << a)); ll bon = (x & (1ll << b)); if (aon && !bon) { rem.push_back(x); } if (!aon && bon) { add.push_back(x ^ (1ll << a) ^ (1ll << b)); } } for (auto x : rem) states.erase(x); for (auto x : add) states.insert(x); add.clear(); rem.clear(); } return states.size()&1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M; vec<pair<int, int>> ms(M); rep (i, 0, M) { cin >> ms[i].x >> ms[i].y; --ms[i].x, --ms[i].y; } reverse(all(ms)); rep (i, 1, N+1) { cout << solve(i, ms) << " "; } cout << "\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 59 60 61 62 63 64 65 66 | #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif #define x first #define y second #define ir(a, x, b) ((a) <= (x) && (x) <= (b)) #define vec vector #define rep(i, a, b) for (int i = a; i < (b); ++i) #define all(x) (x).begin(), (x).end() #define sz(x) (ll)(x).size() using ll = long long; int N, M; int solve(const int K, const vec<pair<int, int>>& ms) { set<ll> states; ll init = (1ll << K)-1; rep (i, K, N+1) { states.insert(init); init <<= 1; } // debug(states); vec<ll> add, rem; rep (i, 0, sz(ms)) { debug(i); auto [a, b] = ms[i]; for (auto x : states) { ll aon = (x & (1ll << a)); ll bon = (x & (1ll << b)); if (aon && !bon) { rem.push_back(x); } if (!aon && bon) { add.push_back(x ^ (1ll << a) ^ (1ll << b)); } } for (auto x : rem) states.erase(x); for (auto x : add) states.insert(x); add.clear(); rem.clear(); } return states.size()&1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M; vec<pair<int, int>> ms(M); rep (i, 0, M) { cin >> ms[i].x >> ms[i].y; --ms[i].x, --ms[i].y; } reverse(all(ms)); rep (i, 1, N+1) { cout << solve(i, ms) << " "; } cout << "\n"; return 0; } |