#include "bits/stdc++.h" using namespace std; #define all(x) x.begin(),x.end() template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #define ASSERT(...) 42 #endif typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin >> n >> m; vi ans(n+1); string s(n,'?'); vector<pi> es(m); for(auto& [u,v] : es) cin >> u >> v,--u,--v; auto check = [&]() { vi zs(n+1),os(n+1); for(int i=0;i<n;++i) { zs[i+1]=zs[i]+(s[i]=='0'); os[i+1]=os[i]+(s[i]=='1'); } for(int i=0;i<n;++i) { for(int j=i;j<n;++j) { if(zs[j+1]-zs[i]) break; if(os[j+1]-os[i]==os[n]) { ans[j-i+1]^=1; } } } }; auto rec = [&](auto&& self, int at) -> void { string before=s; while(at<m) { auto [u,v] = es[at]; if(s[u]=='?' and s[v]=='?') { s[u]=s[v]='1'; self(self,at+1); s[u]=s[v]='0'; self(self,at+1); s=before; return; } else { if(s[u]=='1' or s[v]=='0') swap(s[u],s[v]); at++; } } check(); s=before; return; }; rec(rec,0); ans.erase(ans.begin()); cout << ans << ' ' << '\n'; /* split into two groups? 2^(n/2) */ }
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 | #include "bits/stdc++.h" using namespace std; #define all(x) x.begin(),x.end() template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #define ASSERT(...) 42 #endif typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin >> n >> m; vi ans(n+1); string s(n,'?'); vector<pi> es(m); for(auto& [u,v] : es) cin >> u >> v,--u,--v; auto check = [&]() { vi zs(n+1),os(n+1); for(int i=0;i<n;++i) { zs[i+1]=zs[i]+(s[i]=='0'); os[i+1]=os[i]+(s[i]=='1'); } for(int i=0;i<n;++i) { for(int j=i;j<n;++j) { if(zs[j+1]-zs[i]) break; if(os[j+1]-os[i]==os[n]) { ans[j-i+1]^=1; } } } }; auto rec = [&](auto&& self, int at) -> void { string before=s; while(at<m) { auto [u,v] = es[at]; if(s[u]=='?' and s[v]=='?') { s[u]=s[v]='1'; self(self,at+1); s[u]=s[v]='0'; self(self,at+1); s=before; return; } else { if(s[u]=='1' or s[v]=='0') swap(s[u],s[v]); at++; } } check(); s=before; return; }; rec(rec,0); ans.erase(ans.begin()); cout << ans << ' ' << '\n'; /* split into two groups? 2^(n/2) */ } |