#include <iostream> #include <vector> #include <algorithm> #include <cmath> #define st first #define nd second typedef long long ll; using namespace std; vector<pair<int, int>> swaps; int solve(ll mask, int i) { if (i == -1) return 1; pair<int, int> p = swaps[i]; if (((mask&(1LL<<p.st))>0) == ((mask&(1LL<<p.nd))>0)) { return solve(mask, i-1); } if ((mask&(1LL<<p.nd)) == 0) return 0; return solve(mask, i-1) + solve(mask^(1LL<<p.st)^(1LL<<p.nd), i-1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; swaps.resize(m); for (int i = 0; i < m; i++) { cin >> swaps[i].st >> swaps[i].nd; } for (int i = 1; i <= n; i++) { int ans = 0; for (int j = 1; j <= n-i+1; j++) { ll mask = 0; for (int k = j; k < j+i; k++) { mask |= (1LL<<k); } ans += solve(mask, m-1); } cout << ans%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 | #include <iostream> #include <vector> #include <algorithm> #include <cmath> #define st first #define nd second typedef long long ll; using namespace std; vector<pair<int, int>> swaps; int solve(ll mask, int i) { if (i == -1) return 1; pair<int, int> p = swaps[i]; if (((mask&(1LL<<p.st))>0) == ((mask&(1LL<<p.nd))>0)) { return solve(mask, i-1); } if ((mask&(1LL<<p.nd)) == 0) return 0; return solve(mask, i-1) + solve(mask^(1LL<<p.st)^(1LL<<p.nd), i-1); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; swaps.resize(m); for (int i = 0; i < m; i++) { cin >> swaps[i].st >> swaps[i].nd; } for (int i = 1; i <= n; i++) { int ans = 0; for (int j = 1; j <= n-i+1; j++) { ll mask = 0; for (int k = j; k < j+i; k++) { mask |= (1LL<<k); } ans += solve(mask, m-1); } cout << ans%2 << ' '; } } |