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
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
int n,m,a,b;
std::vector<std::string> state;
int results[36];
int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(NULL);
    std::cin>>n>>m;
    state.push_back("");
    for(int i=0;i<n;i++){
        state[0]+='?';
        results[i]=0;
    }
    for(int i=0;i<m;i++){
        std::cin>>a>>b;
        a--;b--;
        int pre=state.size();
        for(int j=0;j<pre;j++){
            if(state[j][a]=='?'&&state[j][b]=='?') {
                state.push_back(state[j]);
                state[j][a] = '0';
                state[j][b] = '0';
                state.back()[a] = '1';
                state.back()[b] = '1';
            }else
            if(state[j][b]=='0'||state[j][a]=='1'){
                std::swap(state[j][b],state[j][a]);
            }
        }
    }
    int zap=0;
    for(int j=0;j<n;j++){
        if(state[0][j]=='?'){
            zap++;
            for(int i=1;i<=zap;i++)
                results[i]++;
        }else{
            zap=0;
        }
    }
    //std::cerr<<state[0]<<"\n";
    for(int i=1;i<state.size();i++){

        //std::cerr<<state[i]<<"\n";
        int jed=0;
        int pzap=0;
        int kzap=0;
        bool finish=false;
        for(int j=0;j<n;j++){
            if(!finish){
                if(jed==0){
                    if(state[i][j]=='?')
                        pzap++;
                    if(state[i][j]=='0')
                        pzap=0;
                    if(state[i][j]=='1')
                        jed++;
                }else{
                    if(state[i][j]=='?')
                        kzap++;
                    if(state[i][j]=='0')
                        finish=true;
                    if(state[i][j]=='1') {
                        jed+=1+kzap;
                        kzap=0;
                    }
                }
            }else{
                if(state[i][j]=='1'){
                    jed=0;
                    kzap=0;
                    pzap=0;
                }
            }

        }
        if(jed!=0)
            for(int j=0;j<=pzap+kzap;j++)
                results[j+jed]+=std::min(std::min(j,kzap),std::min(pzap,pzap+kzap-j))+1;

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