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
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <tuple>

#define CHECK_BIT(var, pos) ((var) & (1LL << (pos)))

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    int n, m;
    std::cin >> n >> m;

    std::vector<std::pair<int, int>> moves(m);
    long long multiples[n];

    multiples[0] = 1;
    for (int i = 1; i < n; i++)
    {
        multiples[i] = multiples[i - 1] * 2;
    }

    for (int i = 0; i < m; i++)
    {
        std::cin >> moves[i].first >> moves[i].second;
    }

    std::reverse(moves.begin(), moves.end());

    for (int i = 1; i <= n; i++)
    {
        std::unordered_map<long long, bool> s;

        long long val = 0;

        for (int j = 0; j < i; j++)
        {
            val *= 2;
            val++;
        }

        for (int j = 0; j < n - i + 1; j++)
        {
            s[val] = true;
            val *= 2;
        }

        for (int j = 0; j < m; j++)
        {
            int a = moves[j].first - 1;
            int b = moves[j].second - 1;

            std::unordered_map<long long, bool> toRemove;
            std::unordered_map<long long, bool> toAdd;

            for (auto it = s.begin(); it != s.end(); it++)
            {
                if (CHECK_BIT(it->first, a) && !CHECK_BIT(it->first, b))
                {
                    toRemove[it->first] = true;
                }
                else if (CHECK_BIT(it->first, b) && !CHECK_BIT(it->first, a))
                {
                    toAdd[it->first + multiples[a] - multiples[b]] = true;
                }
            }

            for (auto it = toRemove.begin(); it != toRemove.end(); it++)
            {
                s.erase(it->first);
            }

            for (auto it = toAdd.begin(); it != toAdd.end(); it++)
            {
                s[it->first] = true;
            }
        }

        std::cout << s.size() % 2 << " ";
    }

    std::cout << std::endl;

    return 0;
}