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
//
//  main.cpp
//  des
//
//  Created by Michał Kowalski on 15/03/2024.
//

#include <iostream>
#include <vector>
#include <bitset>
#include <cmath>
using namespace std;
long long swapBits(long long x, long long a, long long b);
bool has1(long long val);
bool has2(long long val);
bool has3(long long val);
bool has4(long long val);
bool has5(long long val);
bool has6(long long val);
bool has7(long long val);
bool has8(long long val);
bool has9(long long val);
bool hasN(long long val, long long start);
int K,O;

vector<int> orders;

long long apply_orders(long long num) {
    long long NUM = num;
    for (int i=0;i<orders.size();i+=2) {
        int a = orders[i];
        int b = orders[i+1];
        NUM = swapBits(NUM, a-1, b-1);
    }
    return NUM;
}

long long swapBits(long long x, long long a, long long b)
{
    bitset<40> val(x);
    if (val.test(a) == true && val.test(b) == false) {
        val.flip(a);
        val.flip(b);
        return val.to_ullong();
    }
    return x;
}

int W[40];

int main(int argc, const char * argv[]) {
    
    scanf("%d %d",&K,&O);
    for (int i=0;i<O;++i) {
        int a,b;
        scanf("%d %d",&a,&b);
        orders.push_back(a);
        orders.push_back(b);
    }
    int len = (1<<(K)) - 1;
    for (long long k=1;k<=len;++k) {
        long long val = apply_orders(k);
        if (has1(val)) W[1]++;
        else if (has2(val)) W[2]++;
        else if (has3(val)) W[3]++;
        else if (has4(val)) W[4]++;
        else if (has5(val)) W[5]++;
        else if (has6(val)) W[6]++;
        else if (has7(val)) W[7]++;
        else if (has8(val)) W[8]++;
        else if (has9(val)) W[9]++;
        else if (hasN(val, pow(2,10)-1)) W[10]++;
        else if (hasN(val, pow(2,11)-1)) W[11]++;
        else if (hasN(val, pow(2,12)-1)) W[12]++;
        else if (hasN(val, pow(2,13)-1)) W[13]++;
        else if (hasN(val, pow(2,14)-1)) W[14]++;
        else if (hasN(val, pow(2,15)-1)) W[15]++;
        else if (hasN(val, pow(2,16)-1)) W[16]++;
        else if (hasN(val, pow(2,17)-1)) W[17]++;
        else if (hasN(val, pow(2,18)-1)) W[18]++;
        else if (hasN(val, pow(2,19)-1)) W[19]++;
        else if (hasN(val, pow(2,20)-1)) W[20]++;
        else if (hasN(val, pow(2,21)-1)) W[21]++;
        else if (hasN(val, pow(2,22)-1)) W[22]++;
        else if (hasN(val, pow(2,23)-1)) W[23]++;
        else if (hasN(val, pow(2,24)-1)) W[24]++;
        else if (hasN(val, pow(2,25)-1)) W[25]++;
        else if (hasN(val, pow(2,26)-1)) W[26]++;
        else if (hasN(val, pow(2,27)-1)) W[27]++;
        else if (hasN(val, pow(2,28)-1)) W[28]++;
        else if (hasN(val, pow(2,29)-1)) W[29]++;
        else if (hasN(val, pow(2,30)-1)) W[30]++;
        else if (hasN(val, pow(2,31)-1)) W[31]++;
        else if (hasN(val, pow(2,32)-1)) W[32]++;
        else if (hasN(val, pow(2,33)-1)) W[33]++;
        else if (hasN(val, pow(2,34)-1)) W[34]++;
        else if (hasN(val, pow(2,35)-1)) W[35]++;
    }

    for (int i=1;i<=K;++i) {
        printf("%d ",W[i]%2);
    }
    return 0;
}

bool has1(long long val) {
    for (int x=0;x<35;++x) {
        if (val == (1 << x)) {
            return true;
        }
    }
    return false;
}

bool has2(long long val) {
    for (int x=0;x<35;++x) {
        if (val == (3 << x)) {
            return true;
        }
    }
    return false;
}

bool has3(long long val) {
    for (int x=0;x<35;++x) {
        if (val == (7 << x)) {
            return true;
        }
    }
    return false;
}

bool has4(long long val) {
    for (int x=0;x<35;++x) {
        if (val == (15 << x)) {
            return true;
        }
    }
    return false;
}

bool has5(long long val) {
    for (int x=0;x<35;++x) {
        if (val == (31 << x)) {
            return true;
        }
    }
    return false;
}

bool has6(long long val) {
    for (int x=0;x<35;++x) {
        if (val == (63 << x)) {
            return true;
        }
    }
    return false;
}

bool has7(long long val) {
    for (int x=0;x<35;++x) {
        if (val == (127 << x)) {
            return true;
        }
    }
    return false;
}

bool has8(long long val) {
    for (int x=0;x<35;++x) {
        if (val == (255 << x)) {
            return true;
        }
    }
    return false;
}

bool has9(long long val) {
    for (int x=0;x<35;++x) {
        if (val == (511 << x)) {
            return true;
        }
    }
    return false;
}

bool hasN(long long val, long long start) {
    for (int x=0;x<35;++x) {
        if (val == (start << x)) {
            return true;
        }
    }
    return false;
}