#include <bits/stdc++.h> constexpr int MAX_ORDERS_NUM = 1'004; long long n, m; std::pair<int, int> orders[MAX_ORDERS_NUM]; bool output[MAX_ORDERS_NUM]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); std::cin >> n >> m; for (int i = 0; i < m; ++i) { std::cin >> orders[i].first >> orders[i].second; } long long number_of_combinations = 1 << n; for (long long i = 0; i < number_of_combinations; ++i) { long long order = i; for (int j = 0; j < m; ++j) { if (order & (1 << (orders[j].first - 1)) && !(order & (1 << (orders[j].second - 1)))) { order ^= (1 << (orders[j].first - 1)); order ^= (1 << (orders[j].second - 1)); } } int num_of_segments = order & 1; int num_of_soldiers = order & 1; for (int j = 1; j < n; ++j) { if (order & (1 << j)) { ++num_of_soldiers; } if (order & (1 << j) && !(order & (1 << (j - 1)))) { ++num_of_segments; } } if (num_of_segments == 1) { output[num_of_soldiers] ^= 1; } } for (int i = 1; i <= n; ++i) { if (output[i]) { std::cout << 1 << ' '; } else { std::cout << 0 << ' '; } } 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 60 | #include <bits/stdc++.h> constexpr int MAX_ORDERS_NUM = 1'004; long long n, m; std::pair<int, int> orders[MAX_ORDERS_NUM]; bool output[MAX_ORDERS_NUM]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); std::cin >> n >> m; for (int i = 0; i < m; ++i) { std::cin >> orders[i].first >> orders[i].second; } long long number_of_combinations = 1 << n; for (long long i = 0; i < number_of_combinations; ++i) { long long order = i; for (int j = 0; j < m; ++j) { if (order & (1 << (orders[j].first - 1)) && !(order & (1 << (orders[j].second - 1)))) { order ^= (1 << (orders[j].first - 1)); order ^= (1 << (orders[j].second - 1)); } } int num_of_segments = order & 1; int num_of_soldiers = order & 1; for (int j = 1; j < n; ++j) { if (order & (1 << j)) { ++num_of_soldiers; } if (order & (1 << j) && !(order & (1 << (j - 1)))) { ++num_of_segments; } } if (num_of_segments == 1) { output[num_of_soldiers] ^= 1; } } for (int i = 1; i <= n; ++i) { if (output[i]) { std::cout << 1 << ' '; } else { std::cout << 0 << ' '; } } return 0; } |