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

void solve() {
    int n, m; cin >> n >> m;
    vector<pair<int, int>> e(m);
    for(int i = 0; i < m; i++) {
        cin >> e[i].first >> e[i].second;
        e[i].first--;
        e[i].second--;
    }
    vector<long long> ans(n, 0LL);
    for(int i = 1; i < (1 << n); i++) {
        vector<int> v(n);
        int _i = i;
        int sum = 0;
        for(int j = 0; j < n; j++) {
            v[j] = _i & 1;
            _i >>= 1;
            sum += v[j];
        }
        for(auto x : e) {
            if(v[x.first] == 1 && v[x.second] == 0) {
                swap(v[x.first], v[x.second]);
            }
        }
        int last = 0, str = 0;
        for(int j = 0; j < n; j++) {
            if(v[j] == 1 && last != 1) {
                str++;
            }
            last = v[j];
        }
        if(str == 1) ans[sum - 1] = (ans[sum - 1] + 1) % 2;
    }
    for(int i = 0; i < n; i++) cout << ans[i] << " ";
    cout << "\n";
}

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

    solve();
    return 0;
}