#include <bits/stdc++.h> using namespace std; int Res[36]; int kolor[36]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,m; cin >> n >> m; vector <pair<int,int> > V(m); for (int i = 0; i < m;i++){ cin >> V[i].first >> V[i].second; } for (int i = 0; i < (1 << n);i++){ int copy = i; int liczba = 0; for (int j = 1;j <= n;j++){ if(copy % 2 == 1){ kolor[j] = 1; liczba++; } else{ kolor[j] = 0; } copy /= 2; } for (int j = 0; j < m;j++){ int a = V[j].first; int b = V[j].second; if(kolor[a] == 1 && kolor[b] == 0){ kolor[b] = 1; kolor[a] = 0; } } int mini = n + 1; int maks = -1; for (int j = 1; j <= n;j++){ if(kolor[j] == 1){ mini = min(mini,j); maks = max(maks,j); } } if(maks - mini + 1 == liczba){ Res[liczba]++; } } 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 | #include <bits/stdc++.h> using namespace std; int Res[36]; int kolor[36]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,m; cin >> n >> m; vector <pair<int,int> > V(m); for (int i = 0; i < m;i++){ cin >> V[i].first >> V[i].second; } for (int i = 0; i < (1 << n);i++){ int copy = i; int liczba = 0; for (int j = 1;j <= n;j++){ if(copy % 2 == 1){ kolor[j] = 1; liczba++; } else{ kolor[j] = 0; } copy /= 2; } for (int j = 0; j < m;j++){ int a = V[j].first; int b = V[j].second; if(kolor[a] == 1 && kolor[b] == 0){ kolor[b] = 1; kolor[a] = 0; } } int mini = n + 1; int maks = -1; for (int j = 1; j <= n;j++){ if(kolor[j] == 1){ mini = min(mini,j); maks = max(maks,j); } } if(maks - mini + 1 == liczba){ Res[liczba]++; } } for (int i = 1; i <= n;i++){ cout << Res[i] % 2 << " "; } } |