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
#include <cstdio>
#include <algorithm>

#define REP(a, n) for (int a = 0; a < (n); ++a)
#define FOR(a, b, c) for (int a = (b); a <= (c); ++a)
#define FORD(a, b, c) for (int a = (b); a >= (c); --a)

using namespace std;

//////////////////////

#define X 2

int wyn[40], N, Z;
int zam[2000][2];
int cur[40];

void ocen_wolna() {
    REP(kon, N+1)
        REP(pocz, kon) {
            bool ok = 1;
            REP(i, N)
                if (((i<pocz || i>=kon) && cur[i]==1) || (i>=pocz && i<kon && cur[i]==0)) {
                    ok = false; break;
                }
            if (ok) wyn[kon-pocz]++;
        }
}

void ocen() {
    int f1=-1, l1=-1;
    REP(i, N)
        if (cur[i]==1) {f1 = i; break;}
    if (f1>=0) {
        FORD(i, N-1, 0)
            if (cur[i]==1) {l1 = i; break;}
        FOR(i, f1, l1)
            if (cur[i]==0) return;
        int len = l1-f1+1;
        int fX = 0, lX = 0;
        FORD(i, f1-1, 0)
            if (cur[i]==X) ++fX; else break;
        FOR(i, l1+1, N-1)
            if (cur[i]==X) ++lX; else break;
        if (fX<lX) swap(fX,lX); // lX jest <= fX
        for(int p = 0; p <= lX; p += 2)
            wyn[len+p]++; // += 1+p;
        if (lX%2==0) FOR(p, lX+1, fX)
            wyn[len+p]++; // += 1+lX
        for (int p = fX+lX; p >= fX+1; p-=2)
            wyn[len+p]++; // += 1+fX+lX-p; 
    }
    else {
        int s = 0;
        while (s<N) {
            while (s<N && cur[s]==0) s++;
            if (s==N) break;
            int k = s+1;
            while (k<N && cur[k]==X) k++;
            for (int p = k-s; p>0; p -= 2)
                wyn[p]++;
                s = k;
        }
    }
}

void licz(int poz) {
/*    fprintf(stderr, "poz: %d\n", poz);
    REP(i, N)
        fprintf(stderr, "%d ", cur[i]);
    fprintf(stderr, "\n");
*/    if (poz==Z) { ocen(); return; }
    if (cur[zam[poz][0]]==X && cur[zam[poz][1]]==X) {
        cur[zam[poz][0]] = cur[zam[poz][1]] = 0;
        licz(poz+1);
        cur[zam[poz][0]] = cur[zam[poz][1]] = 1;
        licz(poz+1);
        cur[zam[poz][0]] = X;
        cur[zam[poz][1]] = X;
    }
    else
    if (cur[zam[poz][0]]==0 || cur[zam[poz][1]]==1) {
        licz(poz+1);
    }
    else {
        swap(cur[zam[poz][0]], cur[zam[poz][1]]);
        licz(poz+1);
        swap(cur[zam[poz][0]], cur[zam[poz][1]]);
    }
//    fprintf(stderr, "return %d\n", poz);
}

int main() {
    scanf("%d%d", &N, &Z);
    REP(a, Z) {
        scanf("%d%d", &zam[a][0], &zam[a][1]); --zam[a][0]; --zam[a][1];
    }
    REP(a, N)
        cur[a] = X;
    licz(0);
    REP(a, N)
        printf("%d%s", wyn[a+1]%2, a==N-1?" \n":" ");
}