#include <bits/stdc++.h> using namespace std; using namespace std::chrono; #define REP(i, n) for (LL i = 0; i < (LL)n; i++) #define ST first #define ND second #define MP make_pair #define PB push_back typedef vector<int> VI; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef set<int> SI; typedef long long LL; #ifdef DEBUG const bool debug = true; #else const bool debug = false; #endif // #define MULTI_TASK true const int INF = 1000 * 1000 * 1000; const LL INFLL = 1e18; const int MAKSN = 35 + 13; const LL MOD = 123456789LL; LL N, M, k, l, a, b, c, d; VPII v; long long ans = 0; void zeruj() { v.clear(); } void readIn() { cin >> N >> M; REP(i, M) { cin >> a >> b; a--; b--; v.PB({a, b}); } } bool bitLit(LL mask, LL pos) { return mask & (1ll << pos); } bool check(LL mask) { LL i = 0; while (!bitLit(mask, i) && i < N) { i++; } while (bitLit(mask, i) && i < N) { i++; } while (i < N) { if (bitLit(mask, i)) return false; i++; } return true; } LL simulateChanges(LL mask) { REP(i, M) { LL a = v[i].ST, b = v[i].ND; if (bitLit(mask, a) && !bitLit(mask, b)) { mask ^= (1ll << a); mask ^= (1ll << b); } } return mask; } void printMask(LL mask) { REP(i, N) { cerr << ((mask & (1ll << i)) != 0) << " "; } cerr << "\n"; } void solve() { auto start = high_resolution_clock::now(); for (LL mask = 1; mask < (1ll << N); mask++) { auto end = high_resolution_clock::now(); std::chrono::duration<double> elapsed_seconds = end - start; if (elapsed_seconds.count() > 3.8) { break; } if (check(simulateChanges(mask))) ans ^= (1ll << __builtin_popcountll(mask)); } for (LL i = 1; i <= N; i++) { cout << ((ans & (1ll << i)) != 0) << " "; } cout << "\n"; } int main() { ios_base::sync_with_stdio(0); #ifdef MULTI_TASK int test; cin >> test; while (test--) { #endif zeruj(); readIn(); solve(); #ifdef MULTI_TASK } #endif 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 | #include <bits/stdc++.h> using namespace std; using namespace std::chrono; #define REP(i, n) for (LL i = 0; i < (LL)n; i++) #define ST first #define ND second #define MP make_pair #define PB push_back typedef vector<int> VI; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef set<int> SI; typedef long long LL; #ifdef DEBUG const bool debug = true; #else const bool debug = false; #endif // #define MULTI_TASK true const int INF = 1000 * 1000 * 1000; const LL INFLL = 1e18; const int MAKSN = 35 + 13; const LL MOD = 123456789LL; LL N, M, k, l, a, b, c, d; VPII v; long long ans = 0; void zeruj() { v.clear(); } void readIn() { cin >> N >> M; REP(i, M) { cin >> a >> b; a--; b--; v.PB({a, b}); } } bool bitLit(LL mask, LL pos) { return mask & (1ll << pos); } bool check(LL mask) { LL i = 0; while (!bitLit(mask, i) && i < N) { i++; } while (bitLit(mask, i) && i < N) { i++; } while (i < N) { if (bitLit(mask, i)) return false; i++; } return true; } LL simulateChanges(LL mask) { REP(i, M) { LL a = v[i].ST, b = v[i].ND; if (bitLit(mask, a) && !bitLit(mask, b)) { mask ^= (1ll << a); mask ^= (1ll << b); } } return mask; } void printMask(LL mask) { REP(i, N) { cerr << ((mask & (1ll << i)) != 0) << " "; } cerr << "\n"; } void solve() { auto start = high_resolution_clock::now(); for (LL mask = 1; mask < (1ll << N); mask++) { auto end = high_resolution_clock::now(); std::chrono::duration<double> elapsed_seconds = end - start; if (elapsed_seconds.count() > 3.8) { break; } if (check(simulateChanges(mask))) ans ^= (1ll << __builtin_popcountll(mask)); } for (LL i = 1; i <= N; i++) { cout << ((ans & (1ll << i)) != 0) << " "; } cout << "\n"; } int main() { ios_base::sync_with_stdio(0); #ifdef MULTI_TASK int test; cin >> test; while (test--) { #endif zeruj(); readIn(); solve(); #ifdef MULTI_TASK } #endif return 0; } |