#include <bits/stdc++.h>
#ifdef LOC
#include "debuglib.h"
#else
#define deb(...)
#define DBP(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define rep(i, b, e) for (int i = (b); i < (e); i++)
#define each(a, x) for (auto& a : (x))
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
int n, m;
vector<pii> ops;
vi mask, ans;
void countMask() {
int firstOne = n, lastOne = -1;
rep(i, 0, n) if (mask[i] == 2) {
firstOne = min(firstOne, i);
lastOne = i;
}
rep(b, 0, n) {
if (b > firstOne) break;
if (mask[b] == 0) continue;
int e = b+1;
while (e < n && mask[e] != 0) e++;
if (e <= lastOne) continue;
rep(i, b, e) {
ans[max(lastOne-i+1, 1)] ^= 1;
ans[e-i+1] ^= 1;
if (mask[i] == 2) break;
}
b = e;
}
}
void solve(int i) {
if (i >= sz(ops)) {
countMask();
} else {
auto [x, y] = ops[i];
if (mask[x] == 1 && mask[y] == 1) {
for (int v : {0, 2}) {
mask[x] = mask[y] = v;
solve(i+1);
}
mask[x] = mask[y] = 1;
} else {
bool s = (mask[x] > mask[y]);
if (s) swap(mask[x], mask[y]);
solve(i+1);
if (s) swap(mask[x], mask[y]);
}
}
}
void run() {
cin >> n >> m;
ops.resize(m);
each(e, ops) {
cin >> e.x >> e.y;
e.x--; e.y--;
}
mask.resize(n, 1);
ans.resize(n+2, 0);
solve(0);
bool cur = 0;
rep(i, 1, n+1) {
cur ^= ans[i];
cout << cur << ' ';
}
cout << '\n';
}
int main() {
cin.sync_with_stdio(0); cin.tie(0);
cout << fixed << setprecision(10);
run();
cout << flush; _Exit(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 | #include <bits/stdc++.h> #ifdef LOC #include "debuglib.h" #else #define deb(...) #define DBP(...) #endif using namespace std; using ll = long long; using vi = vector<int>; using pii = pair<int, int>; #define pb push_back #define mp make_pair #define x first #define y second #define rep(i, b, e) for (int i = (b); i < (e); i++) #define each(a, x) for (auto& a : (x)) #define all(x) (x).begin(), (x).end() #define sz(x) int((x).size()) int n, m; vector<pii> ops; vi mask, ans; void countMask() { int firstOne = n, lastOne = -1; rep(i, 0, n) if (mask[i] == 2) { firstOne = min(firstOne, i); lastOne = i; } rep(b, 0, n) { if (b > firstOne) break; if (mask[b] == 0) continue; int e = b+1; while (e < n && mask[e] != 0) e++; if (e <= lastOne) continue; rep(i, b, e) { ans[max(lastOne-i+1, 1)] ^= 1; ans[e-i+1] ^= 1; if (mask[i] == 2) break; } b = e; } } void solve(int i) { if (i >= sz(ops)) { countMask(); } else { auto [x, y] = ops[i]; if (mask[x] == 1 && mask[y] == 1) { for (int v : {0, 2}) { mask[x] = mask[y] = v; solve(i+1); } mask[x] = mask[y] = 1; } else { bool s = (mask[x] > mask[y]); if (s) swap(mask[x], mask[y]); solve(i+1); if (s) swap(mask[x], mask[y]); } } } void run() { cin >> n >> m; ops.resize(m); each(e, ops) { cin >> e.x >> e.y; e.x--; e.y--; } mask.resize(n, 1); ans.resize(n+2, 0); solve(0); bool cur = 0; rep(i, 1, n+1) { cur ^= ans[i]; cout << cur << ' '; } cout << '\n'; } int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); run(); cout << flush; _Exit(0); } |
English