Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- edges = []
- queue = []
- l = []
- num = int(input())
- output = []
- output1 = ""
- Inbound_degree = [0 for _ in range(num)]
- n = 10
- while n != "":
- try:
- n = input()
- if n != "":
- n = list(map(int, n.split()))
- edges.append(n)
- Inbound_degree[n[1]] += 1
- except EOFError:
- break
- for ind, i in enumerate(Inbound_degree):
- if i == 0:
- queue.append(ind)
- else:
- l.append(ind)
- while len(queue) != 0:
- output1 += " ".join(map(str, Inbound_degree)) + "\n" + " ".join(map(str, queue)) + "\n"
- for i in edges:
- if i[0] == queue[0]:
- Inbound_degree[i[1]] -= 1
- for i in l:
- if Inbound_degree[i] == 0:
- queue.append(i)
- l.remove(i)
- el = queue.pop(0)
- output = [el] + output
- bul = False
- for i in Inbound_degree:
- if i != 0 and len(queue) == 0:
- bul = True
- break
- print(output1[:len(output1) - 1])
- if bul:
- print("None")
- else:
- print(*output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement