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
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
int main(){
    
    ios_base::sync_with_stdio(0);
    int n, m; cin >> n >> m;
    
    ll a,b; vector<vector<ll>> v(2);
    for(int i = 1; i <= n; ++i){
        for(int j = 0; j <= (n - i); ++j){ a = 0;
            for(ll k = j; k <= j + i - 1; ++k){a += (1ll << k);}
            v[0].emplace_back(a);
        }
    }
    
    ll x,y; vector<pii> kr(m);
    for(int i = 0; i < m; ++i){
        cin >> kr[i].first >> kr[i].second;
    }
    
    bool p = 1;
    for(int i = m - 1; ~i; --i){
        a = kr[i].first; b = kr[i].second; v[p].clear();
        for(int j = 0; j < (int)v[p ^ 1].size(); ++j){
            x = v[p ^ 1][j] & (1ll << (a - 1)); y = v[p ^ 1][j] & (1ll << (b - 1));
            if((x && y) || (!x && !y)) v[p].emplace_back(v[p ^ 1][j]);
            if(!x && y){
                v[p].emplace_back(v[p ^ 1][j]);
                v[p].emplace_back(v[p ^ 1][j] - (1ll << (b - 1)) + (1ll << (a - 1)));
            }
        }
        p ^= 1;
    }
    
    vector<int> wyn(n + 1); p ^= 1;
    for(int i = 0; i < (int)v[p].size(); ++i){
        wyn[__builtin_popcountll(v[p][i])]^=1;
    }
    
    
    for(int i = 1; i <= n; ++i) cout << wyn[i] << " ";
    cout << "\n";
}