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
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, lower, upper) for(int (i) = (lower); i <= (int)(upper); (i)++)
#define FORD(i, upper, lower) for(int (i) = (upper); i >= (int)(lower); (i)--)

struct op {
    int from;
    int to;
};

int n, m;
op a[1001];
int ans[36];

int cntBits(unsigned long long x) {
    int res = 0;
    for(unsigned long long i = 0; i < 64; i++) {
        if(x & (1LL << i)) {
            res++;
        }
    }
    return res;
}

bool testOps(unsigned long long x) {
    FOR(i, 1, m) {
        int from = a[i].from, to = a[i].to;
        if((x & (1LL << from)) && !(x & (1LL << to))) {
            x |= (1LL << to);
            x ^= (1LL << from);
        }
    }
    bool started = 0;
    bool stopped = 0;
    FOR(i, 0, 63) {
        if(x & (1LL << i)) {
            if(!started) {
                started = 1;
            } 
            else if(stopped) {
                return 0;
            }
        }
        else if(started) {
            stopped = 1;
        }
    }
    return 1;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
    cin >> n >> m;
    FOR(i, 1, m) {
        cin >> a[i].from >> a[i].to;
        a[i].from--; a[i].to--;
    }
    unsigned long long mask = 1;
    for(mask; mask <= pow(2, n) - 1; mask++) {
        int i = cntBits(mask);

        if(testOps(mask)) {
            ans[i]++;// = !ans[i];
            //cout << mask << ' ' << i << '\n';
        }
    }
    FOR(i, 1, n) {
        cout << ans[i] % 2 << ' ';
    }
}