#include <bits/stdc++.h> using namespace std; typedef long long ll; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll i; int n,m; cin>>n>>m; pair<int,int> zmiany[m]; for (i = 0; i < m; i++){ cin>>zmiany[i].first>>zmiany[i].second; zmiany[i].first--; zmiany[i].second--; } int wy[n+1]; for (i = 1; i <= n; i++) wy[i] = 0; for (i = 1; i < (1<<n); i++){ int ile = 0; bool tab[n]; for (int k = 0; k < n; k++){ if (i&(1<<k)){ ile++; tab[k] = 1; }else{ tab[k] = 0; } } for (auto j : zmiany){ if (tab[j.first] && !tab[j.second]){ swap(tab[j.first],tab[j.second]); } } bool koniec = 0; bool good = 1; for (int k = 0; k < n; k++){ if (tab[k] == 1 && koniec){ good = 0; break; } if (k != n-1){ if (tab[k] == 1 && tab[k+1] == 0) koniec = 1; } } wy[ile] += good; } for (i = 1; i <= n; i++) cout<<wy[i]%2<<" "; cout<<"\n"; return 0; }
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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll i; int n,m; cin>>n>>m; pair<int,int> zmiany[m]; for (i = 0; i < m; i++){ cin>>zmiany[i].first>>zmiany[i].second; zmiany[i].first--; zmiany[i].second--; } int wy[n+1]; for (i = 1; i <= n; i++) wy[i] = 0; for (i = 1; i < (1<<n); i++){ int ile = 0; bool tab[n]; for (int k = 0; k < n; k++){ if (i&(1<<k)){ ile++; tab[k] = 1; }else{ tab[k] = 0; } } for (auto j : zmiany){ if (tab[j.first] && !tab[j.second]){ swap(tab[j.first],tab[j.second]); } } bool koniec = 0; bool good = 1; for (int k = 0; k < n; k++){ if (tab[k] == 1 && koniec){ good = 0; break; } if (k != n-1){ if (tab[k] == 1 && tab[k+1] == 0) koniec = 1; } } wy[ile] += good; } for (i = 1; i <= n; i++) cout<<wy[i]%2<<" "; cout<<"\n"; return 0; } |