// https://sio2.mimuw.edu.pl/c/pa-2024-1/p/des/ #include <bits/stdc++.h> #define st first #define nd second #define pb push_back #define all(x) x.begin(), x.end() #define rep(i, a) for (int i = 0; i < (a); i++) #define rep1(i, a) for (int i = 1; i <= (a); i++) using namespace std; typedef long long ll; typedef pair<int, int> pi; vector<pi> tab; int res[40]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; rep(i, m) { int a, b; cin >> a >> b; tab.pb({a, b}); } int mask = 1; for (unsigned int j = 1; j < (1 << m); j++) { unsigned int mask = j; // cerr << '\n' << 'j' << j << '\n'; rep1(i, 4) cerr << ((mask & (1 << (i - 1))) > 0); // cerr << '\n'; rep(i, m) { auto [a, b] = tab[i]; // cerr << a << ',' << b << ' ' << (mask & (1 << (a - 1))) << ' ' // cerr<< (mask & (1 << (b - 1))) << '\n'; if (mask & (1 << (a - 1)) && !(mask & (1 << (b - 1)))) { mask |= (1 << (b - 1)); mask &= ~(1 << (a - 1)); } rep1(i, 4) cerr << ((mask & (1 << (i - 1))) > 0); // cerr << '\n'; } int lo = -1, ma = -1; for (int i = 0; i < 30; i++) { if (mask & (1 << i) && lo == -1) lo = i; if (!(mask & (1 << i)) && lo != -1) { ma = i; break; } } if (__builtin_popcount(mask) == ma - lo) res[__builtin_popcount(mask)]++; // cerr << j << ':' << __builtin_popcount(mask) << ' ' << lo << ' ' << // ma << '\n'; } rep1(i, n) cout << res[i] % 2 << ' '; }
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 | // https://sio2.mimuw.edu.pl/c/pa-2024-1/p/des/ #include <bits/stdc++.h> #define st first #define nd second #define pb push_back #define all(x) x.begin(), x.end() #define rep(i, a) for (int i = 0; i < (a); i++) #define rep1(i, a) for (int i = 1; i <= (a); i++) using namespace std; typedef long long ll; typedef pair<int, int> pi; vector<pi> tab; int res[40]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; rep(i, m) { int a, b; cin >> a >> b; tab.pb({a, b}); } int mask = 1; for (unsigned int j = 1; j < (1 << m); j++) { unsigned int mask = j; // cerr << '\n' << 'j' << j << '\n'; rep1(i, 4) cerr << ((mask & (1 << (i - 1))) > 0); // cerr << '\n'; rep(i, m) { auto [a, b] = tab[i]; // cerr << a << ',' << b << ' ' << (mask & (1 << (a - 1))) << ' ' // cerr<< (mask & (1 << (b - 1))) << '\n'; if (mask & (1 << (a - 1)) && !(mask & (1 << (b - 1)))) { mask |= (1 << (b - 1)); mask &= ~(1 << (a - 1)); } rep1(i, 4) cerr << ((mask & (1 << (i - 1))) > 0); // cerr << '\n'; } int lo = -1, ma = -1; for (int i = 0; i < 30; i++) { if (mask & (1 << i) && lo == -1) lo = i; if (!(mask & (1 << i)) && lo != -1) { ma = i; break; } } if (__builtin_popcount(mask) == ma - lo) res[__builtin_popcount(mask)]++; // cerr << j << ':' << __builtin_popcount(mask) << ' ' << lo << ' ' << // ma << '\n'; } rep1(i, n) cout << res[i] % 2 << ' '; } |