from itertools import combinations
n, m = [int(x) for x in input().split()]
swaps = []
for i in range(m):
swaps.append([int(x) for x in input().split()])
result = []
def generate_ones(size, count):
for positions in combinations(range(size), count):
p = [0] * size
for i in positions:
p[i] = 1
yield p
def swap(combination):
for s in swaps:
if(combination[s[0]-1]==1 and combination[s[1]-1]==0):
combination[s[0]-1] = 0
combination[s[1]-1] = 1
return combination
def check(order):
test = "".join(str(x) for x in order)
return "0" not in test.strip("0")
for i in range(1,n+1):
if i == 1:
result.append(n % 2)
elif i == n:
result.append(1)
else:
counter = 0
for c in generate_ones(n,i):
swaped = swap(c)
is_ok = check(swaped)
if is_ok:
counter += 1
result.append(counter % 2)
print(" ".join(str(x) for x in result))
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 | from itertools import combinations n, m = [int(x) for x in input().split()] swaps = [] for i in range(m): swaps.append([int(x) for x in input().split()]) result = [] def generate_ones(size, count): for positions in combinations(range(size), count): p = [0] * size for i in positions: p[i] = 1 yield p def swap(combination): for s in swaps: if(combination[s[0]-1]==1 and combination[s[1]-1]==0): combination[s[0]-1] = 0 combination[s[1]-1] = 1 return combination def check(order): test = "".join(str(x) for x in order) return "0" not in test.strip("0") for i in range(1,n+1): if i == 1: result.append(n % 2) elif i == n: result.append(1) else: counter = 0 for c in generate_ones(n,i): swaped = swap(c) is_ok = check(swaped) if is_ok: counter += 1 result.append(counter % 2) print(" ".join(str(x) for x in result)) |
English