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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define sn second

typedef long long ll;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef pair<char, char> PC;
typedef pair<int, int> PI;

struct Mask {
  ll value;
  ll mask;
};

bool operator<(Mask a, Mask b) {
  if (a.value != b.value) {
    return a.value < b.value;
  } else {
    return a.mask < b.mask;
  }
}

void print(ll &num) {
  // Assuming you want to represent the number using 64 bits
  // since long long is typically 64 bits in C++
  bitset<64> b(num);
  cout << b.to_string() << endl;
}

vector<ll> ONES(41, 0);

void init() {
  ONES[1] = 1LL;
  ONES[2] = 3LL;
  ONES[3] = 7LL;
  ONES[4] = 15LL;
  ONES[5] = 31LL;
  ONES[6] = 63LL;
  ONES[7] = 127LL;
  ONES[8] = 255LL;
  ONES[9] = 511LL;
  ONES[10] = 1023LL;
  ONES[11] = 2047LL;
  ONES[12] = 4095LL;
  ONES[13] = 8191LL;
  ONES[14] = 16383LL;
  ONES[15] = 32767LL;
  ONES[16] = 65535LL;
  ONES[17] = 131071LL;
  ONES[18] = 262143LL;
  ONES[19] = 524287LL;
  ONES[20] = 1048575LL;
  ONES[21] = 2097151LL;
  ONES[22] = 4194303LL;
  ONES[23] = 8388607LL;
  ONES[24] = 16777215LL;
  ONES[25] = 33554431LL;
  ONES[26] = 67108863LL;
  ONES[27] = 134217727LL;
  ONES[28] = 268435455LL;
  ONES[29] = 536870911LL;
  ONES[30] = 1073741823LL;
  ONES[31] = 2147483647LL;
  ONES[32] = 4294967295LL;
  ONES[33] = 8589934591LL;
  ONES[34] = 17179869183LL;
  ONES[35] = 34359738367LL;
  ONES[36] = 68719476735LL;
  ONES[37] = 137438953471LL;
  ONES[38] = 274877906943LL;
  ONES[39] = 549755813887LL;
  ONES[40] = 1099511627775LL;
}

const char ANY = '2';
vector<PC> was = {{'0', '1'}, {'1', '1'}, {'1', '0'}, {'0', '0'}, {ANY, ANY},
                  {ANY, '1'}, {'1', ANY}, {ANY, '0'}, {'0', ANY}};

vector<PC> is = {{'0', '1'}, {'1', '1'}, {'0', '1'}, {'0', '0'}};

bool is_bit_set(Mask &x, int i, char v) {
  if (v == '1') {
    return (x.value & (1LL << i)) != 0;
  } else if (v == '0') {
    return (x.value & (1LL << i)) == 0;
  } else {
    return (x.mask & (1LL << i)) != 0;
  }
}

bool match(Mask &m, int p, int q, int i) {
  bool first = is_bit_set(m, p, ANY) || is_bit_set(m, p, is[i].first);
  bool second = is_bit_set(m, q, ANY) || is_bit_set(m, q, is[i].second);
  return (first && second);
}

void set_bit(Mask &x, int i, char v) {
  if (v == '1') {
    x.value |= (1LL << i);
    x.mask &= ~(1LL << i);
  } else if (v == '0') {
    x.value &= ~(1LL << i);
    x.mask &= ~(1LL << i);
  } else {
    x.mask |= (1LL << i);
  }
}

Mask build_mask(Mask &m, int p, int q, int i) {
  Mask new_mask;
  new_mask.value = m.value;
  new_mask.mask = m.mask;
  set_bit(new_mask, p, was[i].first);
  set_bit(new_mask, q, was[i].second);
  return new_mask;
}

int nxt(int current) { return (current + 1) % 2; }

int build_set(int n, Mask &mask0, vector<PI> &M) {
  //   cout << "_>" << mask0 << endl;
  set<Mask> S[2];
  int current = 0;

  int r0 = 0;

  S[current].insert(mask0);

  for (int move = M.size() - 1; move >= 0; move--) {
    int p = M[move].first;
    int q = M[move].second;

    if (S[current].empty()) break;

    for (Mask mask : S[current]) {
      VB matches(4, false);
      for (int i = 0; i < 4; i++) matches[i] = match(mask, p, q, i);

      if (matches[0] && matches[1] && matches[2] && matches[3]) {
        S[nxt(current)].insert(build_mask(mask, p, q, 4));
        matches[0] = false;
        matches[1] = false;
        matches[2] = false;
        matches[3] = false;
      } else if (matches[0] && matches[1]) {
        S[nxt(current)].insert(build_mask(mask, p, q, 5));
        matches[0] = false;
        matches[1] = false;
      } else if (matches[1] && matches[2]) {
        S[nxt(current)].insert(build_mask(mask, p, q, 6));
        matches[1] = false;
        matches[2] = false;
      } else if (matches[2] && matches[3]) {
        S[nxt(current)].insert(build_mask(mask, p, q, 7));
        matches[2] = false;
        matches[3] = false;
      } else if (matches[1] && matches[3]) {
        S[nxt(current)].insert(build_mask(mask, p, q, 8));
        matches[1] = false;
        matches[3] = false;
      }

      for (int i = 0; i < 4; i++) {
        if (matches[i]) {
          S[nxt(current)].insert(build_mask(mask, p, q, i));
        }
      }
    }

    S[current].clear();
    current = nxt(current);
  }

  for (Mask mask : S[current]) {
    int r1 = 1;
    if (mask.mask > 1) {
      r1 = 0;
    }
    r0 += r1;
    r0 %= 2;
  }

  return r0;
}

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

  vector<PI> M(m);

  for (int i = 0; i < m; i++) {
    cin >> M[i].first >> M[i].second;
    M[i].first--;
    M[i].second--;
  }

  init();
  for (int k = 1; k <= n; k++) {
    int r = 0;
    Mask mask;
    mask.value = ONES[k];
    mask.mask = 0;

    for (int start = 0; start <= n - k; start++) {
    //   cout << mask.value << " ";
    //   print(mask.value);
    //   cout << endl;
      r += build_set(n, mask, M);
      r %= 2;

      mask.value = mask.value << 1;
    }
    // cout << r << endl;
    cout << r << " ";
  }
  cout << endl;

  //   for (int i = 0; i < 4; i++) {
  //     string mask0 = mask;
  //     mask0[i] = '1';
  //     build_set(n, mask0, M);
  //   }

  return 0;
}