#include <bits/stdc++.h>
using namespace std;
int n,m,k, a[1002], b[1002];
bool f, bz, bj, arr[36], res[36];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i=1; i<=m; i++)
cin >> a[i] >> b[i];
for(int bit=1; bit<(1<<n); bit++)
{
k = __builtin_popcount(bit); f = 1; bz = 0; bj = 0;
for(int i=1; i<=n; i++) arr[i] = (bit & (1 << (i-1)));
for(int i=1; i<=m; i++)
if(arr[a[i]] && !arr[b[i]])
swap(arr[a[i]], arr[b[i]]);
if(k > 1)
{
for(int i=1; i<=n; i++)
{
if(arr[i])
{
if(bz) f = 0;
bj = 1;
}
else
{
if(bj) bz = 1;
}
}
}
res[k]^=f;
}
for(int i=1; i<=n; i++) cout << res[i] << ' ';
}
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 | #include <bits/stdc++.h> using namespace std; int n,m,k, a[1002], b[1002]; bool f, bz, bj, arr[36], res[36]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i=1; i<=m; i++) cin >> a[i] >> b[i]; for(int bit=1; bit<(1<<n); bit++) { k = __builtin_popcount(bit); f = 1; bz = 0; bj = 0; for(int i=1; i<=n; i++) arr[i] = (bit & (1 << (i-1))); for(int i=1; i<=m; i++) if(arr[a[i]] && !arr[b[i]]) swap(arr[a[i]], arr[b[i]]); if(k > 1) { for(int i=1; i<=n; i++) { if(arr[i]) { if(bz) f = 0; bj = 1; } else { if(bj) bz = 1; } } } res[k]^=f; } for(int i=1; i<=n; i++) cout << res[i] << ' '; } |
English