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
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>

using namespace std;

vector<pair<long long, long long>> moves;
vector<int> out;
long long n, m;

long long nobits(long long i){
    long long ot = 0;
    while(i){
        if(i&1) ot++;
        i>>=1;
    }
    return ot;
}

bool isGood(long long cn){
    vector<long long> look;
    look.assign(n, 0);
    long long k = 0;
    while(cn){
        if(cn&1) look[k] = 1;
        cn>>=1;
        k++;
    }

    for(pair<long long, long long> mv : moves){
        if(look[mv.first] == 1 and look[mv.second] == 0) swap(look[mv.first], look[mv.second]);
    }

    bool st = 0;
    bool ed = 0;
    for(long long i = 0; i<n; i++){
        if(look[i] == 1) st = 1;
        if(look[i] == 0 and st) ed = 1;
        if(look[i] == 1 and ed == 1) return false;
    }
    return true;
}

int main(){
    cin>>n>>m;

    for(long long i = 0; i<m; i++){
        long long a, b;
        cin>>a>>b;
        a--; b--;
        moves.push_back({a, b});
    }

    out.assign(n+1, 0);

    long long ubound = 1;
    ubound<<=n;

    for(long long i = 1; i<ubound; i++){
        out[nobits(i)] ^= (int)isGood(i);
    }

    for(long long i = 1; i<=n; i++){
        cout<<out[i]<<" ";
    }

    return 0;
}