#include <iostream>
#include <vector>
using  namespace std;
bool ready[40];
bool rest[40];
vector <pair <int, int> > changes;
bool isOK(int n)
{
    int first_ready = 0;
    for(int i = 1; i <= n; i++)
    {
        if(ready[i])
        {
            if(!first_ready)
                first_ready = i;
            else if(!ready[i - 1])
                return false;
        }
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        int a, b;
        cin >> a >> b;
        changes.push_back({a, b});
    }
    for(int mask = 1; mask < (1 << n);  mask++)
    {
        int k = 0, mask2 = mask;
        for(int j = 1; j <= n; j++)
        {
            if(mask & (1 << (j - 1)))
            {
                k++;
                ready[j] = true;
            }
            else
                ready[j] = false;
        }
        for(auto change: changes)
        {
            int a = change.first, b = change.second;
            if(ready[a] && (!ready[b]))
            {
                swap(ready[a], ready[b]);
            }
        }
        if(isOK(n))
            rest[k] = rest[k] ^ 1;
    }
    for(int k = 1; k <= n; k++)
    {
        cout << rest[k] << ' ';
    }
    return 0;
}
        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  | #include <iostream> #include <vector> using namespace std; bool ready[40]; bool rest[40]; vector <pair <int, int> > changes; bool isOK(int n) { int first_ready = 0; for(int i = 1; i <= n; i++) { if(ready[i]) { if(!first_ready) first_ready = i; else if(!ready[i - 1]) return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for(int i = 1; i <= m; i++) { int a, b; cin >> a >> b; changes.push_back({a, b}); } for(int mask = 1; mask < (1 << n); mask++) { int k = 0, mask2 = mask; for(int j = 1; j <= n; j++) { if(mask & (1 << (j - 1))) { k++; ready[j] = true; } else ready[j] = false; } for(auto change: changes) { int a = change.first, b = change.second; if(ready[a] && (!ready[b])) { swap(ready[a], ready[b]); } } if(isOK(n)) rest[k] = rest[k] ^ 1; } for(int k = 1; k <= n; k++) { cout << rest[k] << ' '; } return 0; }  | 
            
        
                    English