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
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector <pair <int, int> > v(m);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		v[i] = {a, b};
	}
	vector <int> res(n);
	for (int i = 0; i < (1 << n); i++) {
		vector <bool> temp(n);
		int cnt = -1;
		for (int j = 0; j < n; j++) {
			if ((i >> j) & 1) {
				temp[j] = 1;
				cnt++;
			}
		}
		for (int j = 0; j < m; j++) {
			if (temp[v[j].ff])
				swap(temp[v[j].ff], temp[v[j].ss]);
		}
		int c = 0;
		for (int j = 0; j < n; j++) {
			if (temp[j]) {
				if (j == 0 || !temp[j-1])
					c++;
			}
		}
		if (c == 1) {
			res[cnt]++;
			res[cnt] %= 2;
		}
	}
	for (auto i : res)
		cout << i << " ";
}