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
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

auto &operator<<(auto &o, pair<auto, auto> p) {
	return o << "(" << p.st << ", " << p.nd << ")"; }
auto operator<<(auto &o, auto x)->decltype(end(x), o) {
	o << "{"; int i=0; for(auto e: x) o << ", " + 2*!i++ << e;
	return o << "}"; }
#ifdef LOCAL
#define deb(x...) cerr << "[" #x "]: ", [](auto...$) { \
					((cerr << $ << "; "),...) << endl; }(x)
#else
#define deb(...)
#endif

int n;

using mask = pair<ll, ll>;

int what(mask &p, int bit) {
	int res = -1;
	res += p.st >> bit & 1;
	res += (p.nd >> bit & 1) << 1;
	return res;
}

mask sett(mask p, int bit, int to) {
	p.st ^= p.st & (1ll << bit);
	p.nd ^= p.nd & (1ll << bit);
	p.st ^= (ll(to == 0) << bit);
	p.nd ^= (ll(to == 1) << bit);
	return p;
}

void add(mask &m, vi &ans) {
	int first = n, last = -1;
	FOR(i, 0, n) {
		if(what(m, i) == 1) {
			first = min(first, i);
			last = i;
		}
	}
	if(last == -1) {
		FOR(l, 0, n) FOR(r, l, n) {
			if(what(m, r) == 0) break;
			ans[r - l] ^= 1;
		}
	}
	else {
		FOR(i, first, last + 1) if(what(m, i) == 0) return;
		for(int l = first; l >= 0; l--) {
			if(what(m, l) == 0) break;
			for(int r = last; r < n; r++) {
				if(what(m, r) == 0) break;
				ans[r - l] ^= 1;
			}
		}
	}
}

auto &operator<<(auto &o, mask p) {
	o << "(";
	FOR(i, 0, n) {
		char c = '0' + what(p, i);
		if(c < '0') c = '?';
		o << c;
	}
	return o << ")";
}

void solve() {
	int mm;
	cin >> n >> mm;
	vector<pii> edges(mm);
	for(auto &edg: edges) {
		int a, b;
		cin >> a >> b;
		edg = {a - 1, b - 1};
	}
	vector<mask> masks = {{0, 0}};
	int maks = 0;
	for(auto &[from, to]: edges) {
		vector<mask> change;
		change.reserve(sz(masks));
		for(auto &m: masks) {
			int from_bit = what(m, from);
			int to_bit = what(m, to);
			if(from_bit == 0 || to_bit == 1) change.pb(m);
			else if(from_bit == 1 || to_bit == 0) {
				m = sett(m, to, from_bit);
				m = sett(m, from, to_bit);
				change.pb(m);
			}
			else {
				change.pb(sett(sett(m, from, 0), to, 0));
				change.pb(sett(sett(m, from, 1), to, 1));
			}
		}
		sort(all(change));
		masks.clear();
		FOR(i, 0, sz(change)) {
			if(i + 1 < sz(change) && change[i] == change[i + 1]) i++;
			else masks.pb(change[i]);
		}
		maks = max(maks, sz(masks));
	}
	deb(maks);
	vi ans(n);
	for(auto &m: masks) add(m, ans);
	FOR(i, 0, n) cout << ans[i] << " \n"[i + 1 == n];
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int tt = 1;
	// cin >> tt;
	FOR(te, 0, tt) solve();
	return 0;
}