Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A = []
- n = list(map(int, input().split()))
- for i in range(n[1]):
- A.append(list(map(int, input().split())))
- output = []
- output1 = []
- B = [True] * n[1]
- C = [True] * n[1]
- def Deep(A, vertex, B):
- global output
- output.append(vertex)
- B[vertex] = False
- for ind, i in enumerate(A[vertex]):
- if i == 1 and B[ind] != False:
- Deep(A, ind, B)
- else:
- pass
- def Deep1(A, vertex, B):
- global output1
- B[vertex] = False
- for ind, i in enumerate(A[vertex]):
- if i == 1 and B[ind] != False:
- Deep1(A, ind, B)
- else:
- pass
- output1.append(vertex)
- Deep(A, n[0], B)
- Deep1(A, n[0], C)
- print(" ".join(list(map(str, output))))
- print(" ".join(list(map(str, output1))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement