#include <iostream>
using namespace std;
pair<int,int> rozkazy[1100];
int res[50];
int temp[50][50];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
for(int i = 0 ;i < m ;i ++){
cin>>rozkazy[i].first>>rozkazy[i].second;
rozkazy[i].first--;
rozkazy[i].second--;
}
for(int i = 0 ; i < n ;i ++)
temp[1][i]=1<<i;
for(int i = 2; i<=n ;i ++)
for(int j = 0 ;j < n-i+1 ;j ++)
temp[i][j]=temp[i-1][j]|(1<<(j+i-1));
// for(int i = 1 ;i <=n ;i ++){
// for(int j = 0 ;j < n ;j ++)
// {
// cout<<temp[i][j]<<' ';
// }
// cout<<endl;
// }
// cout<<endl;
for(int i = 1; i < (1<<n) ;i ++)
{
if(__builtin_popcount(i) == 1)
{
res[1]++;
continue;
}
int k = i;
int B= __builtin_popcount(i);
for(int j = 0 ;j < m ;j ++)
{
if((k&(1<<rozkazy[j].first))&&(!(k&(1<<rozkazy[j].second))))
{
k^=1<<rozkazy[j].first;
k^=1<<rozkazy[j].second;
}
}
for(int j =0 ;j <= n-B; j ++)
if((k^temp[B][j])==0){
res[B]++;
// cout<<'('<<i<<','<<j<<')'<<' ';;
}
}
// cout<<endl;
for(int i = 1 ;i <= n ;i ++)
cout<<res[i]%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 | #include <iostream> using namespace std; pair<int,int> rozkazy[1100]; int res[50]; int temp[50][50]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; for(int i = 0 ;i < m ;i ++){ cin>>rozkazy[i].first>>rozkazy[i].second; rozkazy[i].first--; rozkazy[i].second--; } for(int i = 0 ; i < n ;i ++) temp[1][i]=1<<i; for(int i = 2; i<=n ;i ++) for(int j = 0 ;j < n-i+1 ;j ++) temp[i][j]=temp[i-1][j]|(1<<(j+i-1)); // for(int i = 1 ;i <=n ;i ++){ // for(int j = 0 ;j < n ;j ++) // { // cout<<temp[i][j]<<' '; // } // cout<<endl; // } // cout<<endl; for(int i = 1; i < (1<<n) ;i ++) { if(__builtin_popcount(i) == 1) { res[1]++; continue; } int k = i; int B= __builtin_popcount(i); for(int j = 0 ;j < m ;j ++) { if((k&(1<<rozkazy[j].first))&&(!(k&(1<<rozkazy[j].second)))) { k^=1<<rozkazy[j].first; k^=1<<rozkazy[j].second; } } for(int j =0 ;j <= n-B; j ++) if((k^temp[B][j])==0){ res[B]++; // cout<<'('<<i<<','<<j<<')'<<' ';; } } // cout<<endl; for(int i = 1 ;i <= n ;i ++) cout<<res[i]%2<<' '; } |
English