#include <iostream> #include <queue> #include <string> #include <vector> #define MAXN 35 using namespace std; int n, m; vector<pair<int, int>> comms; int s[MAXN]; int dfs(int c) { if (c < 0) return 1; int res = 0; int a = comms[c].first; int b = comms[c].second; //cerr << "[" << c << "," << s[a] << s[b] << "]"; if (s[a] && !s[b]) return 0; if (!s[a] && s[b]) { s[a] = 1; s[b] = 0; res = dfs(c - 1); s[a] = 0; s[b] = 1; } res += dfs(c - 1); return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; comms.push_back({a - 1, b - 1}); } for (int i = 1; i <= n; i++) { // cerr << "\n <<" << i << "\n"; int res = 0; for (int j = 0; j < n; j++) s[j] = j < i; for (int j = i; j <= n; j++) { int r1 = dfs(comms.size() - 1); res += r1; // for (int k = 0; k < n; k++) { // cerr << s[k] << " "; // } // cerr << "[" << r1 << "\n"; s[j] = 1; s[j - i] = 0; } cout << (res & 1) << " "; } 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 53 54 55 56 57 58 59 | #include <iostream> #include <queue> #include <string> #include <vector> #define MAXN 35 using namespace std; int n, m; vector<pair<int, int>> comms; int s[MAXN]; int dfs(int c) { if (c < 0) return 1; int res = 0; int a = comms[c].first; int b = comms[c].second; //cerr << "[" << c << "," << s[a] << s[b] << "]"; if (s[a] && !s[b]) return 0; if (!s[a] && s[b]) { s[a] = 1; s[b] = 0; res = dfs(c - 1); s[a] = 0; s[b] = 1; } res += dfs(c - 1); return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; comms.push_back({a - 1, b - 1}); } for (int i = 1; i <= n; i++) { // cerr << "\n <<" << i << "\n"; int res = 0; for (int j = 0; j < n; j++) s[j] = j < i; for (int j = i; j <= n; j++) { int r1 = dfs(comms.size() - 1); res += r1; // for (int k = 0; k < n; k++) { // cerr << s[k] << " "; // } // cerr << "[" << r1 << "\n"; s[j] = 1; s[j - i] = 0; } cout << (res & 1) << " "; } cout << "\n"; return 0; } |