#include <iostream> #include <vector> #include <bitset> using namespace std; const int L = 4; vector<pair<int, int>>v; long long bt(long long mask, int ind) { if(ind == -1) return 1; int x = v[ind].first; int y = v[ind].second; if((mask & (1ll << x)) && !(mask & (1ll << y))) return 0; long long answer = 0; if(!(mask & (1ll << x)) && (mask & (1ll << y))) answer += bt(mask ^ (1ll << y) ^ (1ll << x), ind - 1); answer += bt(mask, ind - 1); return answer; } int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; v.resize(m); for(auto &[x, y] : v) { cin >> x >> y; x--; y--; } vector<long long>answer(n + 1); for(int len = 1; len <= n; len++) { for(int k = 0; k + len <= n; k++) { long long mask = ((1ll << len) - 1) << k; answer[len] += bt(mask, m - 1); } } for(int i = 1; i <= n; i++) cout << answer[i] % 2 << " "; cout << "\n"; 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 | #include <iostream> #include <vector> #include <bitset> using namespace std; const int L = 4; vector<pair<int, int>>v; long long bt(long long mask, int ind) { if(ind == -1) return 1; int x = v[ind].first; int y = v[ind].second; if((mask & (1ll << x)) && !(mask & (1ll << y))) return 0; long long answer = 0; if(!(mask & (1ll << x)) && (mask & (1ll << y))) answer += bt(mask ^ (1ll << y) ^ (1ll << x), ind - 1); answer += bt(mask, ind - 1); return answer; } int main() { ios_base::sync_with_stdio(0); int n, m; cin >> n >> m; v.resize(m); for(auto &[x, y] : v) { cin >> x >> y; x--; y--; } vector<long long>answer(n + 1); for(int len = 1; len <= n; len++) { for(int k = 0; k + len <= n; k++) { long long mask = ((1ll << len) - 1) << k; answer[len] += bt(mask, m - 1); } } for(int i = 1; i <= n; i++) cout << answer[i] % 2 << " "; cout << "\n"; return 0; } |