#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i,a,b) for(ll i=a; i<=b; ++i) #define pb push_back #define ssize(v) (ll)(v.size()) #define fi first #define se second constexpr int MAX_N=35+2, MAX_M=1e3+14; ll N, M, rres[MAX_M]; vector<pair<ll,ll>> inp; vector<ll> cbn[2]; void Input(){ int a,b; cin>>N>>M; FOR(i,0,M-1){ cin>>a>>b; inp.pb({--a,--b}); } reverse(inp.begin(),inp.end()); } void Solve(){ ll cCbn; rres[1]=N%2; FOR(k,2,N){ // cout<<"k:"<<k<<"\n"; cCbn=0; FOR(i,0,k-1) cCbn+=(ll)1<<i; cbn[0].clear(); FOR(i,0,N-k){ cbn[0].pb(cCbn); cCbn^=((ll)1<<i); cCbn^=((ll)1<<(i+k)); } FOR(i,0,M-1){ // cout<<" i:"<<i<<": "; cbn[(i+1)%2].clear(); FOR(j,0,ssize(cbn[i%2])-1){ if((!(cbn[i%2][j]&((ll)1<<inp[i].fi)))&&(cbn[i%2][j]&((ll)1<<inp[i].se))){ cbn[(i+1)%2].pb(cbn[i%2][j]); cbn[(i+1)%2].pb(((cbn[i%2][j]^((ll)1<<inp[i].fi))^(ll)1<<inp[i].se)); continue; } if((cbn[i%2][j]&((ll)1<<inp[i].fi))&&(!(cbn[i%2][j]&((ll)1<<inp[i].se)))) continue; cbn[(i+1)%2].pb(cbn[i%2][j]); } // for(auto cEl:cbn[i%2]) cout<<cEl<<", "; // cout<<"\n"; } // cout<<"k:"<<k<<" "<<ssize(cbn[M%2])<<"\n"<<flush; rres[k]=ssize(cbn[M%2])%2; } } void Print(){ FOR(k,1,N) cout<<rres[k]<<" "; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); Input(); Solve(); Print(); }
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 <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i,a,b) for(ll i=a; i<=b; ++i) #define pb push_back #define ssize(v) (ll)(v.size()) #define fi first #define se second constexpr int MAX_N=35+2, MAX_M=1e3+14; ll N, M, rres[MAX_M]; vector<pair<ll,ll>> inp; vector<ll> cbn[2]; void Input(){ int a,b; cin>>N>>M; FOR(i,0,M-1){ cin>>a>>b; inp.pb({--a,--b}); } reverse(inp.begin(),inp.end()); } void Solve(){ ll cCbn; rres[1]=N%2; FOR(k,2,N){ // cout<<"k:"<<k<<"\n"; cCbn=0; FOR(i,0,k-1) cCbn+=(ll)1<<i; cbn[0].clear(); FOR(i,0,N-k){ cbn[0].pb(cCbn); cCbn^=((ll)1<<i); cCbn^=((ll)1<<(i+k)); } FOR(i,0,M-1){ // cout<<" i:"<<i<<": "; cbn[(i+1)%2].clear(); FOR(j,0,ssize(cbn[i%2])-1){ if((!(cbn[i%2][j]&((ll)1<<inp[i].fi)))&&(cbn[i%2][j]&((ll)1<<inp[i].se))){ cbn[(i+1)%2].pb(cbn[i%2][j]); cbn[(i+1)%2].pb(((cbn[i%2][j]^((ll)1<<inp[i].fi))^(ll)1<<inp[i].se)); continue; } if((cbn[i%2][j]&((ll)1<<inp[i].fi))&&(!(cbn[i%2][j]&((ll)1<<inp[i].se)))) continue; cbn[(i+1)%2].pb(cbn[i%2][j]); } // for(auto cEl:cbn[i%2]) cout<<cEl<<", "; // cout<<"\n"; } // cout<<"k:"<<k<<" "<<ssize(cbn[M%2])<<"\n"<<flush; rres[k]=ssize(cbn[M%2])%2; } } void Print(){ FOR(k,1,N) cout<<rres[k]<<" "; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); Input(); Solve(); Print(); } |