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;

string s;
pair <int, int> g[1005];

int solve(string &cur, int idx) {
    if (idx == 0) return 1;

    int i = g[idx].first, j = g[idx].second;
    if (cur[i] == cur[j]) {
        while (idx > 0 && cur[i] == cur[j]) {
            idx--;
            i = g[idx].first, j = g[idx].second;
        }
        return solve(cur, idx);
    }
    else if (cur[i] == '1' && cur[j] == '0') return 0;
    else {
        int left = solve(cur, idx - 1);
        swap(cur[i], cur[j]);
        int right = solve(cur, idx - 1);
        swap(cur[i], cur[j]);
        return (left ^ right);
    }
}

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

    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> g[i].first >> g[i].second;
    }    

    for (int i = 0; i <= n; i++) {
        s.push_back('0');
    }

    cout << n % 2 << ' ';
    for (int i = 2; i < n; i++) {
        for (int j = 1; j <= n; j++) {
            if (j <= i) s[j] = '1';
            else s[j] = '0';
        }
        int ans = solve(s, m);
        for (int j = i + 1; j <= n; j++) {
            s[j] = '1';
            s[j - i] = '0';
            ans ^= solve(s, m);
        }        
        cout << ans << ' ';
    }
    cout << 1 << '\n';
}