#include <bits/stdc++.h> using namespace std; typedef pair<int,int> PII; typedef pair<long long,int> PLI; PII moves[1005]; int res[50]; int main(){ ios_base::sync_with_stdio(0); int n, m; cin>>n>>m; for(int i=0;i<m;i++){ cin>>moves[i].first>>moves[i].second; moves[i].first--; moves[i].second--; } for(int _mask=1;_mask<(1<<n);_mask++){ int mask = _mask; for(int i=0;i<m;i++){ if((mask & (1<<moves[i].first)) != 0 && (mask & (1<<moves[i].second)) == 0){ mask ^= (1<<moves[i].first); mask ^= (1<<moves[i].second); } } int k = 0; int max_bit = 0; int min_bit = 1e9; for(int i=0;i<n;i++){ if(mask & (1<<i)){ max_bit = i; min_bit = min(min_bit, i); k++; } } if(max_bit-min_bit+1 == k) res[k]++; // cout<<mask<<" "<<_mask<<" "<<k<<" "<<max_bit<<" "<<min_bit<<endl; } for(int i=1;i<=n;i++) cout<<res[i]%2<<" "; cout<<endl; }
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 | #include <bits/stdc++.h> using namespace std; typedef pair<int,int> PII; typedef pair<long long,int> PLI; PII moves[1005]; int res[50]; int main(){ ios_base::sync_with_stdio(0); int n, m; cin>>n>>m; for(int i=0;i<m;i++){ cin>>moves[i].first>>moves[i].second; moves[i].first--; moves[i].second--; } for(int _mask=1;_mask<(1<<n);_mask++){ int mask = _mask; for(int i=0;i<m;i++){ if((mask & (1<<moves[i].first)) != 0 && (mask & (1<<moves[i].second)) == 0){ mask ^= (1<<moves[i].first); mask ^= (1<<moves[i].second); } } int k = 0; int max_bit = 0; int min_bit = 1e9; for(int i=0;i<n;i++){ if(mask & (1<<i)){ max_bit = i; min_bit = min(min_bit, i); k++; } } if(max_bit-min_bit+1 == k) res[k]++; // cout<<mask<<" "<<_mask<<" "<<k<<" "<<max_bit<<" "<<min_bit<<endl; } for(int i=1;i<=n;i++) cout<<res[i]%2<<" "; cout<<endl; } |