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

using namespace std;

typedef long long ll;

int a[1010];
int b[1010];
int res[50];

void search_tree(ll base, int inst, int bc) {
    if(inst < 0) {
        res[bc] ^= 1;
        return;
    }

    ll p = (1LL<<(a[inst] - 1));
    ll q = (1LL<<(b[inst] - 1));

    if((bool)(p&base) == (bool)(q&base)) {
        search_tree(base, inst - 1, bc);
        return;
    }

    if((p&base) < (q&base)) {
        search_tree(base, inst - 1, bc);
        search_tree(base^p^q, inst - 1, bc);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

    for(int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
    }

    for(int i = 1; i <= n; i++) {
        ll base = (1LL<<i) - 1;
        for(int j = 0; j <= n - i; j++) {
            search_tree(base<<j, m - 1, i);
        }
    }

    for(int i = 1; i <= n; i++) {
        cout << res[i] << " ";
    }
    cout << "\n";

    return 0;
}