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 <iostream>
using namespace std;
pair<int,int> V[1007];
long long t[37], ta[37];
long long n, m, a, b, x, y, z;
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    for (int i = 0; i < m; i++) 
    {
        cin >> a >> b;
        V[i] = {a-1, b-1};
    }
    for (long long i = 1; i < (1UL<<n); i++) 
    {
        z = i;
        y = 0;
        for (int j = n; j >= 0; j--) 
        {
            if (z / (1UL << j) > 0)
            {
                z -= (1UL << j);
                ta[j] = 1;
                y++;
            }
            else
            {
                ta[j] = 0;
            }
        }
        for(int i=0;i<m;i++)
        {
            if(ta[V[i].first] == 1 && ta[V[i].second] == 0) 
            {
                swap(ta[V[i].first], ta[V[i].second]);
            }
        }
        x = 0;
        if(ta[0] == 1)
        {
            x++;
        }
        for(int j = 1; j < n; j++) 
        {
            if(ta[j] != ta[j-1] && x > 0)
            {
                break;
            }
            else if(ta[j])
            {
                x++;
            }
        }
        if (x == y)
            t[y]++;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << t[i] % 2 << " ";
    }
    cout << endl;
    return 0;
}