#include <cstdio> #include <algorithm> using namespace std; pair<int, int> e[1001]; int ret[36]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d", &e[i].first, &e[i].second); } for (int i = 1; i < (1 << n); i++) { int bits = __builtin_popcount(i); const int cnt = bits; int t = i; for (int j = 0; j < m; j++) { int a = n - e[j].first; int b = n - e[j].second; if (((1 << a) & t) > 0 && ((1 << b) & t) == 0) { t -= (1 << a); t += (1 << b); } } int pos = __builtin_ctz(t); t >>= pos; t++; if (__builtin_popcount(t) == 1) { ret[cnt]++; } } for (int i = 1; i <= n; i++) { printf("%d ", ret[i] % 2); } 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 | #include <cstdio> #include <algorithm> using namespace std; pair<int, int> e[1001]; int ret[36]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d", &e[i].first, &e[i].second); } for (int i = 1; i < (1 << n); i++) { int bits = __builtin_popcount(i); const int cnt = bits; int t = i; for (int j = 0; j < m; j++) { int a = n - e[j].first; int b = n - e[j].second; if (((1 << a) & t) > 0 && ((1 << b) & t) == 0) { t -= (1 << a); t += (1 << b); } } int pos = __builtin_ctz(t); t >>= pos; t++; if (__builtin_popcount(t) == 1) { ret[cnt]++; } } for (int i = 1; i <= n; i++) { printf("%d ", ret[i] % 2); } return 0; } |