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
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <bitset>
#include <cmath>

using namespace std;

int next_set_of_n_elements(int x) {
	int smallest, ripple, new_smallest, ones;

	if (x == 0) return 0;
	smallest = (x & -x);
	ripple = x + smallest;
	new_smallest = (ripple & -ripple);
	ones = ((new_smallest / smallest) >> 1) - 1;
	return ripple | ones;
}

int orders_executed = 0;
int continuous = 0;

int execute_order(pair<int, int> order, int x, int &soldiers) {
	int am = 1 << (soldiers - order.first);
	int sm = ~(1 << (soldiers - order.second));
	
	if (x & am && ~(x | sm)) {
		x |= ~sm;
		x &= ~am;
	}
	
	return x;
}

void print_binary(int x) {
	cout << bitset<8 * sizeof(x)>(x) << endl;
}

bool is_continuous(int x) {
	return !((x + (x & -x)) & x);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m;
	//cin >> n >> m;
	vector<pair<int, int>> orders;
	cin >> n >> m;

	int a, b;

	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		orders.push_back(make_pair(a, b));
	}

	vector<vector<long long>> C(37, vector<long long>(37));

	for (int k = 1; k <= 35; k++) C[0][k] = 0;
	for (int n = 0; n <= 35; n++) C[n][0] = 1;

	for (int n = 1; n <= 35; n++) {
		for (int k = 1; k <= n; k++) {
			C[n][k] = C[n - 1][k - 1] + C[n - 1][k];
		}
	}

	int i;
	int soldiers = n;


	for (int ready_soldiers = 1; ready_soldiers < soldiers; ready_soldiers++) {
		int numbers = C[soldiers][ready_soldiers];

		orders_executed = 0;
		continuous = 0;

		int a = pow(2, ready_soldiers) - 1;
		for (i = 0; i < numbers; i++)
		{
			int a_after = a;

			for (int o = 0; o < orders.size(); o++) {
				a_after = execute_order(orders[o], a_after, soldiers);
			}

			if (is_continuous(a_after))
				continuous++;

			a = next_set_of_n_elements(a);

		}

		cout << continuous % 2 << " ";
	}

	cout << 1 << endl;
}