#include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() pair<int,int>P[1007]; int ans[40], n, m; void rek(int x, vector<int>T) { for(int i=x; i<m; ++i) { if(T[P[i].st]==0 && T[P[i].nd]==0) { T[P[i].st]=1; T[P[i].nd]=1; rek(i+1, T); T[P[i].st]=2; T[P[i].nd]=2; rek(i+1, T); return; } else if(T[P[i].st]==2 || T[P[i].nd]==1) swap(T[P[i].st], T[P[i].nd]); } int mi=n, ma=-1; rep(i, n) if(T[i]==2) { mi=min(mi, i); ma=max(ma, i); } rep(i, n) { for(int j=i; j<n; ++j) { if(T[j]==1) break; if(i<=mi && ma<=j) ans[j-i+1]^=1; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; rep(i, m) { cin >> P[i].st >> P[i].nd; --P[i].st; --P[i].nd; } vector<int>T(n); rek(0, T); rep(i, n) cout << ans[i+1] << " "; cout << '\n'; }
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 | #include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() pair<int,int>P[1007]; int ans[40], n, m; void rek(int x, vector<int>T) { for(int i=x; i<m; ++i) { if(T[P[i].st]==0 && T[P[i].nd]==0) { T[P[i].st]=1; T[P[i].nd]=1; rek(i+1, T); T[P[i].st]=2; T[P[i].nd]=2; rek(i+1, T); return; } else if(T[P[i].st]==2 || T[P[i].nd]==1) swap(T[P[i].st], T[P[i].nd]); } int mi=n, ma=-1; rep(i, n) if(T[i]==2) { mi=min(mi, i); ma=max(ma, i); } rep(i, n) { for(int j=i; j<n; ++j) { if(T[j]==1) break; if(i<=mi && ma<=j) ans[j-i+1]^=1; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; rep(i, m) { cin >> P[i].st >> P[i].nd; --P[i].st; --P[i].nd; } vector<int>T(n); rek(0, T); rep(i, n) cout << ans[i+1] << " "; cout << '\n'; } |