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
73
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
vector <vector <bool>> all_possible[40];
pair <int, vector <bool>> possible;
void gen(int i)
{
    if (i == n)
    {
        if (possible.first == 0) return;
        all_possible[possible.first].push_back(possible.second);
        return;
    }
    possible.second[i] = 1;
    ++possible.first;
    gen(i+1);
    possible.second[i] = 0;
    --possible.first;
    gen(i+1);
}
bool res[40];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    while (possible.second.size() < n)
    {
        possible.second.push_back(0);
    }
    gen(0);
    for (int i = 0; i < m; ++i)
    {
        cin >> a >> b;
        --a, --b;
        for (int j = 1; j <= n; ++j)
        {
            for (int h = 0; h < all_possible[j].size(); ++h)
            {
                if (all_possible[j][h][a] && !all_possible[j][h][b])
                {
                    all_possible[j][h][a] = 0;
                    all_possible[j][h][b] = 1;
                }
            }
        }
    }
    for (int j = 1; j <= n; ++j)
    {
        for (int h = 0; h < all_possible[j].size(); ++h)
        {
            bool st = 0, cnt = 1;
            for (int i = 0; i < n; ++i)
            {
                if (all_possible[j][h][i] && !st)
                {
                    st = 1;
                    continue;
                }
                if (all_possible[j][h][i] && st && !all_possible[j][h][i-1])
                {
                    cnt = 0;
                }
            }
            if (cnt) res[j] = !res[j];
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        if (res[i]) cout << "1 ";
        else cout << "0 ";
    }
}