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
// PA 2024 4B - Desant 3
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <unordered_set>
using namespace std;

void generateAllResults(unordered_set<string> *results, string state, unsigned k, bool containsOne) {
	if (k == state.size()) {
		if (containsOne) {
			results->insert(state);
		}
		return;
	}
	
	generateAllResults(results, state, k + 1, containsOne);
	state[k] = '1';
	generateAllResults(results, state, k + 1, true);
};

int main()
{
	ios_base::sync_with_stdio(0);
	int n, m, a, b;
	bool met1, met10, met101;
	unordered_set<string> results;
	unordered_set<string>::iterator it2;
	string state;
	vector<int> endResults;
	
	cin >> n;
	cin >> m;
	
	state = "";
	for (int i = 0; i < n; ++i) {
		endResults.push_back(0);
		state += '0';
	}
	
	generateAllResults(&results, state, 0, false);
	
	for (int i = 0; i < m; ++i) {
		cin >> a;
		cin >> b;
		--a;
		--b;
		
		for (unordered_set<string>::iterator it = results.begin(); it != results.end();) {
			if ((*it)[a] == '1' && (*it)[b] == '0') {
				state = (*it);
				state[a] = '0';
				state[b] = '1';
				it2 = results.find(state);
				if (it2 == results.end()) {
					results.insert(state);
				} else {
					results.erase(it2);
				}
				it = results.erase(it);
			} else {
				++it;
			}
		}		
		
		/*cout << endl << endl;
		for (unordered_set<string>::iterator it = results.begin(); it != results.end(); ++it) {
			cout << (*it) << endl;
		}
		cout << endl;*/
	}
	
	for (unordered_set<string>::iterator it = results.begin(); it != results.end(); ++it) {
		a = 0;
		met1 = false;
		met10 = false;
		met101 = false;
		for (unsigned i = 0; i < it->size(); ++i) {
			if (met10 && (*it)[i] == '1') {
				met101 = true;
				break;
			}
			if ((*it)[i] == '1') {
				++a;
				met1 = true;
			}
			if (met1 && (*it)[i] == '0') {
				met10 = true;
			}
		}
		
		if (not met101) { 
			endResults[a - 1] = (endResults[a - 1] + 1) % 2;
		}
	}
	
	for (int i = 0; i < n; ++i) {
		cout << endResults[i] << " ";
	}
	cout << endl;
	
	return 0;
}