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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<vector<int>> subsets(const vector<int>& nums) {
    if (nums.size() == 1) {
        return {{}, {nums[0]}};
    }
    vector<vector<int>> subsets1 = subsets(vector<int>(nums.begin() + 1, nums.end()));
    vector<vector<int>> my_subsets;
    for (const vector<int>& s : subsets1) {
        vector<int> temp = {nums[0]};
        temp.insert(temp.end(), s.begin(), s.end());
        my_subsets.push_back(temp);
    }
    my_subsets.insert(my_subsets.end(), subsets1.begin(), subsets1.end());
    return my_subsets;
}

bool validate(const vector<int>& soldiers, int k) {
    int count = 0;
    for (int num : soldiers) {
        if (num == 1) {
            count++;
            if (count == k) {
                return true;
            }
        } else {
            count = 0;
        }
    }
    return false;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> orders(m);
    for (int i = 0; i < m; i++) {
        cin >> orders[i].first >> orders[i].second;
    }

    vector<vector<int>> n_subsets;
    vector<int> nums(n);
    for (int i = 0; i < n; ++i) {
        nums[i] = i + 1;
    }
    n_subsets = subsets(nums);

    vector<int> results(n + 1, 0);

    for (const vector<int>& subset : n_subsets) {
        int k = subset.size();
        if (k == 0) {
            continue;
        }

        vector<int> soldiers(n + 1, 0);
        for (int i : subset) {
            soldiers[i] = 1;
        }

        for (const auto& order : orders) {
            int x = order.first;
            int y = order.second;
            if (soldiers[x] == 1 && soldiers[y] == 0) {
                soldiers[x] = 0;
                soldiers[y] = 1;
            }
        }

        if (validate(soldiers, k)) {
            results[k] = (results[k] + 1) % 2;
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << results[i] << " ";
    }
    cout << endl;

    return 0;
}