#include <iostream> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> commands(m); for (int i = 0; i < m; i++) { cin >> commands[i].first >> commands[i].second; commands[i].first--; commands[i].second--; } for (int k = 1; k <= n; k++) { int count = 0; for (int state = 0; state < (1 << n); state++) { if (__builtin_popcount(state) == k) { int tempState = state; for (auto &cmd : commands) { if ((tempState & (1 << cmd.first)) && !(tempState & (1 << cmd.second))) { tempState ^= (1 << cmd.first); tempState ^= (1 << cmd.second); } } int firstOne = -1, lastOne = -1; for (int i = 0; i < n; i++) { if (tempState & (1 << i)) { if (firstOne == -1) firstOne = i; lastOne = i; } } bool isValid = true; for (int i = firstOne; i <= lastOne; i++) { if (!(tempState & (1 << i))) { isValid = false; break; } } if (isValid) count++; } } cout << count % 2 << " "; } cout << endl; 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 | #include <iostream> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<pair<int, int>> commands(m); for (int i = 0; i < m; i++) { cin >> commands[i].first >> commands[i].second; commands[i].first--; commands[i].second--; } for (int k = 1; k <= n; k++) { int count = 0; for (int state = 0; state < (1 << n); state++) { if (__builtin_popcount(state) == k) { int tempState = state; for (auto &cmd : commands) { if ((tempState & (1 << cmd.first)) && !(tempState & (1 << cmd.second))) { tempState ^= (1 << cmd.first); tempState ^= (1 << cmd.second); } } int firstOne = -1, lastOne = -1; for (int i = 0; i < n; i++) { if (tempState & (1 << i)) { if (firstOne == -1) firstOne = i; lastOne = i; } } bool isValid = true; for (int i = firstOne; i <= lastOne; i++) { if (!(tempState & (1 << i))) { isValid = false; break; } } if (isValid) count++; } } cout << count % 2 << " "; } cout << endl; return 0; } |