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;

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

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

    vector<ll> seqs((1 << n), 1);

    while(m--) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        for(int i = 0; i < seqs.size(); i++) {
            ll seq = i;
            ll a1 = ((1 << a) & seq) >> a, b1 = ((1 << b) & seq) >> b;
            a1 <<= b;
            b1 = ((1 << n) - 1 - (1 << a)) | (b1 << a);
            seq &= b1;
            seq |= a1;

            if(seq != i) {
                seqs[seq] += seqs[i];
                seqs[i] = 0;
            }
        }
    }

    for(int k = 1; k <= n; k++) {
        ll frame = (1 << k) - 1;
        ll sum = 0;
        for(int i = 0; i <= n - k; i++, frame <<= 1) {
            sum += seqs[frame];
            sum %= 2;
        }

        cout << sum << ' ';
    }
    cout << '\n';
}