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

int main() {
    int n, m;
    std::cin >> n >> m;

    std::vector<std::pair<int, int>> orders;
    for (int i = 0; i < m; ++i) {
        int a, b;
        std::cin >> a >> b;
        orders.emplace_back(a, b);
    }

    std::vector<bool> next(n);
    int count = 0;
    std::vector<int> result(n + 1);
    for (;;) {
        for (int i = 0; i < n; ++i) {
            if (next[i] == false) {
                next[i] = true;
                count += 1;
                break;
            } else {
                next[i] = false;
                count -= 1;
            }
        }

        if (count == 0) {
            break;
        }

        auto current = next;
        for (auto [a, b]: orders) {
            a -= 1; b -= 1;
            if (current[a] && !current[b]) {
                current[a] = false; current[b] = true;
            }
        }

        int seen = 0;
        bool ok = true;
        for (auto b: current) {
            if (seen == 0 && b) {
                seen = 1;
            } else if (seen == 1 && !b) {
                seen = 2;
            } else if (seen == 2 && b) {
                ok = false;
                break;
            }
        }
        if (ok) {
            result[count] += 1;
        }
    }

    for (int i = 1; i <= n; ++i) {
        std::cout << result[i] % 2 << " ";
    }
    std::cout << "\n";
}