#ifdef DEBUG #define _GLIBCXX_DEBUG #endif //#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef long double ld; int n, m; const int maxN = 1005; int a[maxN], b[maxN]; int ans[38]; int p[38]; void go(int ind) { if (ind == m) { int cnt_one = 0; for (int c = 0; c < n; c++) { if (p[c] == 1) cnt_one++; } for (int x = 0; x < n; x++) { int cur_one = 0; for (int y = x; y < n; y++) { if (p[y] == 0) break; if (p[y] == 1) cur_one++; if (cur_one == cnt_one) { ans[y - x + 1] ^= 1; } } } return; } if (p[a[ind]] == 1 || p[b[ind]] == 0) { swap(p[a[ind]], p[b[ind]]); go(ind + 1); swap(p[a[ind]], p[b[ind]]); } else if (p[a[ind]] == 0 || p[b[ind]] == 1) { go(ind + 1); } else { p[a[ind]] = 0; p[b[ind]] = 0; go(ind + 1); p[a[ind]] = 1; p[b[ind]] = 1; go(ind + 1); p[a[ind]] = -1; p[b[ind]] = -1; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef DEBUG freopen("input.txt", "r", stdin); #endif cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; --a[i]; --b[i]; } memset(p, -1, sizeof p); go(0); for (int c = 1; c <= n; c++) { cout << ans[c] << " "; } 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #ifdef DEBUG #define _GLIBCXX_DEBUG #endif //#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef long double ld; int n, m; const int maxN = 1005; int a[maxN], b[maxN]; int ans[38]; int p[38]; void go(int ind) { if (ind == m) { int cnt_one = 0; for (int c = 0; c < n; c++) { if (p[c] == 1) cnt_one++; } for (int x = 0; x < n; x++) { int cur_one = 0; for (int y = x; y < n; y++) { if (p[y] == 0) break; if (p[y] == 1) cur_one++; if (cur_one == cnt_one) { ans[y - x + 1] ^= 1; } } } return; } if (p[a[ind]] == 1 || p[b[ind]] == 0) { swap(p[a[ind]], p[b[ind]]); go(ind + 1); swap(p[a[ind]], p[b[ind]]); } else if (p[a[ind]] == 0 || p[b[ind]] == 1) { go(ind + 1); } else { p[a[ind]] = 0; p[b[ind]] = 0; go(ind + 1); p[a[ind]] = 1; p[b[ind]] = 1; go(ind + 1); p[a[ind]] = -1; p[b[ind]] = -1; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef DEBUG freopen("input.txt", "r", stdin); #endif cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i] >> b[i]; --a[i]; --b[i]; } memset(p, -1, sizeof p); go(0); for (int c = 1; c <= n; c++) { cout << ans[c] << " "; } return 0; } |