#include<bits/stdc++.h> using namespace std; const int N = 40; int n = 0, m = 0, ans[N] = {}; vector<array<int, N> > S, T; int main(){ scanf("%d %d", &n, &m); array<int, N> _; _.fill(-1); S.push_back(_); for(int i = 0, u = 0, v = 0 ; i < m ; i ++){ scanf("%d %d", &u, &v); u --, v --; for(array<int, N> &a : S){ if(a[u] == -1 && a[v] == -1){ array<int, N> b = a; a[u] = a[v] = 0, b[u] = b[v] = 1; T.push_back(b); } else if(a[u] == 1 || a[v] == 0) swap(a[u], a[v]); } for(array<int, N> a : T) S.push_back(a); T.clear(); } for(array<int, N> a : S){ int s = n - 1, t = 0; for(int i = 0 ; i < n ; i ++) if(a[i] == 1) s = min(s, i), t = max(t, i); for(int l = 0 ; l < n ; l ++) for(int r = l ; r < n && a[r] != 0 ; r ++) if(l <= s && t <= r) ans[r - l + 1] ^= 1; } for(int k = 1 ; k <= n ; k ++) printf("%d ", ans[k]); 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 | #include<bits/stdc++.h> using namespace std; const int N = 40; int n = 0, m = 0, ans[N] = {}; vector<array<int, N> > S, T; int main(){ scanf("%d %d", &n, &m); array<int, N> _; _.fill(-1); S.push_back(_); for(int i = 0, u = 0, v = 0 ; i < m ; i ++){ scanf("%d %d", &u, &v); u --, v --; for(array<int, N> &a : S){ if(a[u] == -1 && a[v] == -1){ array<int, N> b = a; a[u] = a[v] = 0, b[u] = b[v] = 1; T.push_back(b); } else if(a[u] == 1 || a[v] == 0) swap(a[u], a[v]); } for(array<int, N> a : T) S.push_back(a); T.clear(); } for(array<int, N> a : S){ int s = n - 1, t = 0; for(int i = 0 ; i < n ; i ++) if(a[i] == 1) s = min(s, i), t = max(t, i); for(int l = 0 ; l < n ; l ++) for(int r = l ; r < n && a[r] != 0 ; r ++) if(l <= s && t <= r) ans[r - l + 1] ^= 1; } for(int k = 1 ; k <= n ; k ++) printf("%d ", ans[k]); return 0; } |