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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//GRT_2018
#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define all(x) x.begin(), x.end()
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 40, qax = 1000 + 10;
int n, m;
pi adj[qax];

void swp(int a, int b, ll &mask) {
    ll ea = (mask & (1LL << a));
    ll eb = (mask & (1LL << b));

    mask ^= ea;
    mask ^= eb;

    ea = (((ea > 0 ? 1LL : 0LL)) << b);
    eb = (((eb > 0 ? 1LL : 0LL)) << a);

    mask ^= ea;
    mask ^= eb;
}

int ans[nax];

void solve(ll know, ll mask) {
    //cerr << bitset<8>(know) << "\n";
    //cerr << bitset<8>(mask) << "\n";
    //cerr << "------\n";
    int p1 = -1, p2 = -1;
    for (int i = 0; i < n; ++i) {
        if (know & (1LL << i)) {
            if (mask & (1LL << i)) {
                if (p1 == -1) p1 = i;
                p2 = i;
            }
        }
    }
    if (p1 == -1) {
        //special case
        vi cnt(n + 1);
        fill(all(cnt), 0);

        int last = -1;
        for (int i = 0; i < n; ++i) {
            if (know & (1LL << i)) {
                cnt[i - last - 1]++;
                last = i;
            }
        }
        cnt[(n-1)-last]++;
        
        for (int bck = 1; bck <= n; ++bck) {
            if (cnt[bck] & 1) {
                for (int k = 1; k <= bck; ++k) {
                    int opt = bck - k + 1;
                    opt &= 1;
                    ans[k] ^= opt;
                }
            }
        }
    } else {
        for (int i = p1; i <= p2; ++i) {
            if (know & (1LL << i)) {
                if ((mask & (1LL << i)) == 0) {
                    return;
                }
            }
        }
        
        int a = 0, b = 0;
        for (int i = p1 - 1; i >= 0; --i) {
            if ((know & (1LL << i)) == 0) {
                a++;
            } else {
                break;
            }
        }
        for (int i = p2 + 1; i < n; i++) {
            if ((know & (1LL << i)) == 0) {
                b++;
            } else {
                break;
            }
        }
        for (int k = (p2 - p1 + 1); k <= n; ++k) {
            int k2 = k - (p2 - p1 + 1);
            int up = min(a, k2);
            int down = max(k2 - b, 0);

            int opt = max(0, up - down + 1);
            opt &= 1;
            ans[k] ^= opt;
        }
    }

}

void rec(ll know, ll mask, int step) {
    if (step == m) {
        solve(know, mask);
        return;
    }
    int a = adj[step].ST, b = adj[step].ND;
    bool ka = (know & (1LL << a));
    bool kb = (know & (1LL << b));
    bool bita = (mask & (1LL << a));
    bool bitb = (mask & (1LL << b));

    if (!ka && !kb) {
        know |= (1LL << a);
        know |= (1LL << b);

        rec(know, mask, step + 1);

        mask |= (1LL << a);
        mask |= (1LL << b);

        rec(know, mask, step + 1);
    } else {
        if ((ka && bita) || (kb && !bitb)) {
            swp(a, b, mask);
            swp(a, b, know);
        }

        rec(know, mask, step + 1);
    }
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    cin >> n >> m;
    for (int a,b,i = 0; i < m; ++i) {
        cin >> a >> b;
        a--, b--;
        adj[i] = {a, b};
    }
    rec(0LL, 0LL, 0);

    for (int k = 1; k <= n; ++k) {
        cout << ans[k] << " ";
    }
}