#include <bits/stdc++.h> using namespace std; #define fwd(i, a, n) for (int i = (a); i < (n); i ++) #define rep(i, n) fwd(i, 0, n) #define all(X) begin(X), end(X) #define sz(X) ((int)X.size()) #define st first #define nd second #define pii pair<int, int> #define vi vector<int> #ifdef LOC auto &operator << (auto &out, pair<auto, auto> a) { return out << "(" << a.st << ", " << a.nd << ")"; } auto &operator << (auto &out, auto a) { out << "{"; for (auto b : a) out << b << ", "; return out << "}"; } void dump(auto... x) { ((cerr << x << ", "), ...) << '\n'; } #define debug(x...) cerr << "[" #x "]: ", dump(x) #else #define debug(...) 0 #endif #define maxN 36 #define maxQ 1001 #define B bitset<maxN> int n, q; int SUM[maxN + 1]; int FROM[maxQ], TO[maxQ]; int W[maxN]; void show(B &zero, B &one) { string dbg; rep(i, n) { if (one[i]) { dbg.append("1 "); } else if (zero[i]) { dbg.append("0 "); } else { dbg.append("? "); } } debug(dbg); } void backtrack(B zero, B one, int q_ptr) { int s = -1, t = -1, s_type = -1, t_type = -1; while (q_ptr < q) { s = FROM[q_ptr]; t = TO[q_ptr]; s_type = (zero[s] ? 0 : (one[s] ? 1 : 2)); t_type = (zero[t] ? 0 : (one[t] ? 1 : 2)); if (s_type == 2) { if (t_type == 2) { break; } else if (t_type == 0) { zero[t] = 0; zero[s] = 1; } } else { if (t_type == 2) { if (s_type == 1) { one[s] = 0; one[t] = 1; } } else if (s_type == 1 && t_type == 0) { one[s] = 0; zero[t] = 0; zero[s] = 1; one[t] = 1; } } q_ptr += 1; } if (q_ptr == q) { int max_sum = 0; rep(i, n) { if (zero[i]) { W[i] = -1; } else if (one[i]) { W[i] = 1; max_sum += 1; } else { W[i] = 0; } } rep(i, n) { int cum_sum = 0; int len = 0; fwd(j, i, n) { if (W[j] == -1) { break; } len += 1; cum_sum += W[j]; if (cum_sum == max_sum) SUM[len] ^= 1; } } return; } zero[s] = 1; zero[t] = 1; backtrack(zero, one, q_ptr); zero[s] = 0; zero[t] = 0; one[s] = 1; one[t] = 1; backtrack(zero, one, q_ptr); } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> q; rep(i, q) { cin >> FROM[i] >> TO[i]; FROM[i] --, TO[i] --; } backtrack(B(), B(), 0); fwd(i, 1, n + 1) cout << SUM[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 | #include <bits/stdc++.h> using namespace std; #define fwd(i, a, n) for (int i = (a); i < (n); i ++) #define rep(i, n) fwd(i, 0, n) #define all(X) begin(X), end(X) #define sz(X) ((int)X.size()) #define st first #define nd second #define pii pair<int, int> #define vi vector<int> #ifdef LOC auto &operator << (auto &out, pair<auto, auto> a) { return out << "(" << a.st << ", " << a.nd << ")"; } auto &operator << (auto &out, auto a) { out << "{"; for (auto b : a) out << b << ", "; return out << "}"; } void dump(auto... x) { ((cerr << x << ", "), ...) << '\n'; } #define debug(x...) cerr << "[" #x "]: ", dump(x) #else #define debug(...) 0 #endif #define maxN 36 #define maxQ 1001 #define B bitset<maxN> int n, q; int SUM[maxN + 1]; int FROM[maxQ], TO[maxQ]; int W[maxN]; void show(B &zero, B &one) { string dbg; rep(i, n) { if (one[i]) { dbg.append("1 "); } else if (zero[i]) { dbg.append("0 "); } else { dbg.append("? "); } } debug(dbg); } void backtrack(B zero, B one, int q_ptr) { int s = -1, t = -1, s_type = -1, t_type = -1; while (q_ptr < q) { s = FROM[q_ptr]; t = TO[q_ptr]; s_type = (zero[s] ? 0 : (one[s] ? 1 : 2)); t_type = (zero[t] ? 0 : (one[t] ? 1 : 2)); if (s_type == 2) { if (t_type == 2) { break; } else if (t_type == 0) { zero[t] = 0; zero[s] = 1; } } else { if (t_type == 2) { if (s_type == 1) { one[s] = 0; one[t] = 1; } } else if (s_type == 1 && t_type == 0) { one[s] = 0; zero[t] = 0; zero[s] = 1; one[t] = 1; } } q_ptr += 1; } if (q_ptr == q) { int max_sum = 0; rep(i, n) { if (zero[i]) { W[i] = -1; } else if (one[i]) { W[i] = 1; max_sum += 1; } else { W[i] = 0; } } rep(i, n) { int cum_sum = 0; int len = 0; fwd(j, i, n) { if (W[j] == -1) { break; } len += 1; cum_sum += W[j]; if (cum_sum == max_sum) SUM[len] ^= 1; } } return; } zero[s] = 1; zero[t] = 1; backtrack(zero, one, q_ptr); zero[s] = 0; zero[t] = 0; one[s] = 1; one[t] = 1; backtrack(zero, one, q_ptr); } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> q; rep(i, q) { cin >> FROM[i] >> TO[i]; FROM[i] --, TO[i] --; } backtrack(B(), B(), 0); fwd(i, 1, n + 1) cout << SUM[i] << ' '; cout << '\n'; return 0; } |