#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> #include <climits> using namespace std; using ll = long long; using ul = unsigned long long; using db = long double; using pi = pair<int, int>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pi>; #define mp make_pair #define pb push_back #define eb emplace_back #define x first #define y second template<class T> using V = vector<T>; template<class T, size_t SZ> using AR = array<T,SZ>; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define each(a,x) for (auto& a: x) #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rep(i,a,b) for(int i = (a); i < (b); i++) #define per(i,a,b) for(int i = (b) - 1; i >= (a); i--) #ifdef LOCAL template<class A, class B> auto& operator<<(auto &o, pair<A, B> p) { return o << '(' << p.x << ", " << p.y << ')'; } auto& operator<<(auto& o, auto a) { o << "{"; for (auto b : a) o << b << ", "; return o << "}"; } void dump(auto... x) { ((cerr << x << ", "), ...) << "\n"; } #define debug(x...) cerr << "[" #x "]: ", dump(x) #else #define debug(...) ; #endif template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<class T> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); } template<class T> int upb(V<T>& a, const T& b) { return int(ub(all(a),b)-bg(a)); } template<class T> void remDup(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)),end(v)); } const int M = 1005; const int N = 40; int a[M], b[M]; int res[N]; int n, m; void calc_2() { rep(i,0,n) { rep(j,i+1,n) { int x[2] = {i, i}; int y[2] = {j, j}; rep(k,0,m) { rep(t,0,2) { if (x[t] == a[k] && y[t] == b[k]) continue; if (x[t] == b[k] && y[t] == a[k]) continue; if (x[t] == a[k] && t == 0) x[t] = b[k]; if (y[t] == a[k] && t == 0) y[t] = b[k]; if (x[t] == b[k] && t == 1) x[t] = a[k]; if (y[t] == b[k] && t == 1) y[t] = a[k]; } } if (abs(x[0] - y[0]) == 1) { res[2] ^= 1; } if (x[1]+y[1] == 1 || x[1]+y[1] == (n - 1 + n - 2)) { res[n-2] ^= 1; } else if ((x[1] == 0 && y[1] == n-1) || (y[1] == 0 && x[1] == n-1)) { res[n-2] ^= 1; } } } } void calc_1() { res[1] = n % 2; rep(i,0,n) { int x = i; rep(k,0,m) { if (x == b[k]) x = a[k]; } if (x == 0 || x == n-1) { res[n-1] ^= 1; } } res[n] = 1; } void do_jajco() { calc_1(); calc_2(); rep(i,1,n+1) { cout << res[i] << ' '; } cout << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; rep(i,0,m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } if (m > 50 && n > 26) { do_jajco(); return 0; } const size_t siz = size_t(1) << n; char dp[2][siz]; fill(dp[0], dp[0] + (1 << n), 1); rep(i,0,1<<n) { dp[0][i] = 1; } rep(i,0,m) { int cur = i % 2; int nxt = (i + 1) % 2; memset(dp[nxt], 0, siz); int delta = (1 << a[i]) ^ (1 << b[i]); rep(mask,0,1<<n) { bool has_a = (mask >> a[i]) & 1; bool has_b = (mask >> b[i]) & 1; if (has_a && !has_b) { dp[nxt][mask ^ delta] ^= dp[cur][mask]; } else { dp[nxt][mask] ^= dp[cur][mask]; } } } rep(i,0,n) { int mask = 0; rep(j,i,n) { mask |= (1 << j); int cnt = __builtin_popcount(mask); res[cnt] ^= dp[m & 1][mask]; } } rep(i,1,n+1) cout << res[i] << ' '; 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 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> #include <climits> using namespace std; using ll = long long; using ul = unsigned long long; using db = long double; using pi = pair<int, int>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pi>; #define mp make_pair #define pb push_back #define eb emplace_back #define x first #define y second template<class T> using V = vector<T>; template<class T, size_t SZ> using AR = array<T,SZ>; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define each(a,x) for (auto& a: x) #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rep(i,a,b) for(int i = (a); i < (b); i++) #define per(i,a,b) for(int i = (b) - 1; i >= (a); i--) #ifdef LOCAL template<class A, class B> auto& operator<<(auto &o, pair<A, B> p) { return o << '(' << p.x << ", " << p.y << ')'; } auto& operator<<(auto& o, auto a) { o << "{"; for (auto b : a) o << b << ", "; return o << "}"; } void dump(auto... x) { ((cerr << x << ", "), ...) << "\n"; } #define debug(x...) cerr << "[" #x "]: ", dump(x) #else #define debug(...) ; #endif template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<class T> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); } template<class T> int upb(V<T>& a, const T& b) { return int(ub(all(a),b)-bg(a)); } template<class T> void remDup(vector<T>& v) { sort(all(v)); v.erase(unique(all(v)),end(v)); } const int M = 1005; const int N = 40; int a[M], b[M]; int res[N]; int n, m; void calc_2() { rep(i,0,n) { rep(j,i+1,n) { int x[2] = {i, i}; int y[2] = {j, j}; rep(k,0,m) { rep(t,0,2) { if (x[t] == a[k] && y[t] == b[k]) continue; if (x[t] == b[k] && y[t] == a[k]) continue; if (x[t] == a[k] && t == 0) x[t] = b[k]; if (y[t] == a[k] && t == 0) y[t] = b[k]; if (x[t] == b[k] && t == 1) x[t] = a[k]; if (y[t] == b[k] && t == 1) y[t] = a[k]; } } if (abs(x[0] - y[0]) == 1) { res[2] ^= 1; } if (x[1]+y[1] == 1 || x[1]+y[1] == (n - 1 + n - 2)) { res[n-2] ^= 1; } else if ((x[1] == 0 && y[1] == n-1) || (y[1] == 0 && x[1] == n-1)) { res[n-2] ^= 1; } } } } void calc_1() { res[1] = n % 2; rep(i,0,n) { int x = i; rep(k,0,m) { if (x == b[k]) x = a[k]; } if (x == 0 || x == n-1) { res[n-1] ^= 1; } } res[n] = 1; } void do_jajco() { calc_1(); calc_2(); rep(i,1,n+1) { cout << res[i] << ' '; } cout << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; rep(i,0,m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } if (m > 50 && n > 26) { do_jajco(); return 0; } const size_t siz = size_t(1) << n; char dp[2][siz]; fill(dp[0], dp[0] + (1 << n), 1); rep(i,0,1<<n) { dp[0][i] = 1; } rep(i,0,m) { int cur = i % 2; int nxt = (i + 1) % 2; memset(dp[nxt], 0, siz); int delta = (1 << a[i]) ^ (1 << b[i]); rep(mask,0,1<<n) { bool has_a = (mask >> a[i]) & 1; bool has_b = (mask >> b[i]) & 1; if (has_a && !has_b) { dp[nxt][mask ^ delta] ^= dp[cur][mask]; } else { dp[nxt][mask] ^= dp[cur][mask]; } } } rep(i,0,n) { int mask = 0; rep(j,i,n) { mask |= (1 << j); int cnt = __builtin_popcount(mask); res[cnt] ^= dp[m & 1][mask]; } } rep(i,1,n+1) cout << res[i] << ' '; cout << '\n'; return 0; } |