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
#include <iostream>
#include <vector>

using namespace std;
using pii = pair<int, int>;

int n, m;
vector<pii> orders;
int res[40];

bool good(vector<int> &pos){
	bool wasdiff = pos[0]==1;
	for(int i=0; i<n-1; i++){
		int diff = pos[i+1] - pos[i];
		if(diff > 0){
			if(wasdiff) return false;
			wasdiff = true;
		}
	}
	return true;
}

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	cin>>n>>m;
	orders.resize(m);
	for(int i=0; i<m; i++){
		auto &[a, b] = orders[i];
		cin>>a>>b;
	}
	for(int i=1; i<(1<<n); i++){
		vector<int> pos(n, 0);
		int sz = 0;
		for(int j=0; j<n; j++){
			if(i&(1<<j)){
				sz++;
				pos[j] = 1;
			}else{
				pos[j] = 0;
			}
		}
		for(auto [f, s] : orders){
			f--;
			s--;
			if(pos[f] == 1 && pos[s] == 0){
				swap(pos[f], pos[s]);
			}
		}
		if(good(pos)){
			res[sz]++;
			res[sz] %= 2;
		}
	}
	for(int i=1; i<=n; i++){
		cout<<res[i]<<' ';
	}
	cout<<'\n';
	return 0;
}