-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path음악프로그램.py
More file actions
36 lines (28 loc) · 742 Bytes
/
음악프로그램.py
File metadata and controls
36 lines (28 loc) · 742 Bytes
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
from collections import deque
def topo_sort():
for i in range(1, n + 1):
if indegree[i] == 0:
que.append(i)
while que:
now = que.pop()
res.append(now)
for i in graph[now]:
indegree[i] -= 1
if indegree[i] == 0:
que.append(i)
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
que = deque()
res = []
indegree = [0] * (n + 1)
for _ in range(m):
arr = list(map(int, input().split()))
for i in range(1, len(arr) - 1, 1):
graph[arr[i]].append(arr[i + 1])
indegree[arr[i + 1]] += 1
topo_sort()
if len(res) != n:
print(0)
else:
for item in res:
print(item)