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
#include <bits/stdc++.h>

using namespace std;

int n,m;
long long a,b;
long long covered;
vector<long long> states = {0};
int r[40];
int add[40];

void f(long long state)
{
    //cout<<"state "<<bitset<4>(state)<<endl;
    int last0=-1,first1=-1,last1=-1,first0=n;
    for(int i=0;i<n;i++)
    {
        if(!(covered&(1LL<<i))) continue;

        // covered 1
        if(state&(1LL<<i))
        {
            if(first1==-1) first1=i;
            last1=i;
        }
        // covered 0
        else
        {
            if(first1==-1) last0=i;
            if(first1!=-1&&first0==n) first0=i;
        }
    }

    // impossible
    if(first0<last1) return;

    // only zeros
    if(last1==-1)
    {
        int h = 0;
        for(int i=0;i<n;i++)
        {
            if(covered&(1LL<<i))
            {
                add[h]^=1;
                h=0;
            }
            else h++;
        }
        add[h]^=1;
    }
    // 1 exists
    else
    {
        int ones=last1-first1+1;
        int l1=max(first1-last0-1, 0), l2=max(first0-last1-1, 0);
        for(int x=0;x<=n;x++)
        {
            r[ones+x] ^= max(min(x, l1) - max(x - l2, 0) + 1, 0) % 2;
        }
    }
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%lld%lld",&a,&b);
        a = 1LL << (a-1);
        b = 1LL << (b-1);

        // both covered -> skip
        if((covered&a)&&(covered&b))
        {
            covered = covered | a | b;
            continue;
        }

        // none covered -> consider 00 and 11
        if(!(covered&a)&&!(covered&b))
        {
            for(auto state: states) states.push_back(state|a|b);
            covered = covered | a | b;
            continue;
        }

        vector<long long> h;

        // a covered
        if(covered&a)
        {
            for(auto state: states)
            {
                h.push_back(state|b);
                if(state&a) h.push_back((state^a)|b);
                else h.push_back(state);
            }
        }

        // b covered
        if(covered&b)
        {
            for(auto state: states)
            {
                h.push_back(state);
                if(state&b) h.push_back(state|a);
                else h.push_back(state|b);
            }
        }

        states.clear();
        sort(h.begin(), h.end());
        for(int i=0;i<h.size();i++)
        {
            if(i==h.size()-1||h[i]!=h[i+1]) states.push_back(h[i]);
            else i++;
        }

        covered = covered | a | b;
    }

    for(auto state: states) f(state);

    // count additional
    for(int i=1;i<=n;i++)
    {
        //cout<<i<<" "<<add[i]<<endl;
        if(add[i]%2==0) continue;
        int pos=1;
        for(int j=i;j;j--)
        {
            r[j]^=pos;
            pos^=1;
        }
    }

    for(int i=1;i<=n;i++) printf("%d ", r[i]);

    return 0;
}