Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. A = []
  2. n = list(map(int, input().split()))
  3. for i in range(n[1]):
  4. A.append(list(map(int, input().split())))
  5. output = []
  6. output1 = []
  7. B = [True] * n[1]
  8. C = [True] * n[1]
  9.  
  10. def Deep(A, vertex, B):
  11. global output
  12. output.append(vertex)
  13. B[vertex] = False
  14. for ind, i in enumerate(A[vertex]):
  15. if i == 1 and B[ind] != False:
  16. Deep(A, ind, B)
  17. else:
  18. pass
  19.  
  20. def Deep1(A, vertex, B):
  21. global output1
  22. B[vertex] = False
  23. for ind, i in enumerate(A[vertex]):
  24. if i == 1 and B[ind] != False:
  25. Deep1(A, ind, B)
  26. else:
  27. pass
  28. output1.append(vertex)
  29.  
  30.  
  31. Deep(A, n[0], B)
  32. Deep1(A, n[0], C)
  33. print(" ".join(list(map(str, output))))
  34. print(" ".join(list(map(str, output1))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement