#include <iostream>
constexpr int MAX_N = 35;
constexpr int MAX_M = 1000;
struct {short a, b;} orders[MAX_M];
bool res[MAX_N+1];
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
for(int i = 0; i < m; ++i)
std::cin >> orders[i].a >> orders[i].b,
--orders[i].a, --orders[i].b;
for(long long tab = 1; tab < (1LL<<n); ++tab)
{
long long moved = tab;
for(int k = 0; k < m; ++k)
if((moved&(1LL<<orders[k].a)) && (~moved&(1LL<<orders[k].b)))
moved &= ~(1LL<<orders[k].a),
moved |= 1LL<<orders[k].b;
while(~moved&1) moved >>= 1;
if(__builtin_popcount(moved+1) == 1)
res[__builtin_popcount(moved)] ^= 1;
}
for(int i = 1; i <= n; ++i)
std::cout << res[i] << ' ';
std::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 | #include <iostream> constexpr int MAX_N = 35; constexpr int MAX_M = 1000; struct {short a, b;} orders[MAX_M]; bool res[MAX_N+1]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n, m; std::cin >> n >> m; for(int i = 0; i < m; ++i) std::cin >> orders[i].a >> orders[i].b, --orders[i].a, --orders[i].b; for(long long tab = 1; tab < (1LL<<n); ++tab) { long long moved = tab; for(int k = 0; k < m; ++k) if((moved&(1LL<<orders[k].a)) && (~moved&(1LL<<orders[k].b))) moved &= ~(1LL<<orders[k].a), moved |= 1LL<<orders[k].b; while(~moved&1) moved >>= 1; if(__builtin_popcount(moved+1) == 1) res[__builtin_popcount(moved)] ^= 1; } for(int i = 1; i <= n; ++i) std::cout << res[i] << ' '; std::cout << '\n'; return 0; } |
English