init
This commit is contained in:
commit
851751ea87
82 changed files with 2093 additions and 0 deletions
24
1J.py
Normal file
24
1J.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import heapq
|
||||
|
||||
n = int(input())
|
||||
adj = [[] for _ in range(n + 1)]
|
||||
in_deg = [0] * (n + 1)
|
||||
for i in range(1, n + 1):
|
||||
data = list(map(int, input().split()))
|
||||
if data[0] > 0:
|
||||
for parent in data[1:]:
|
||||
adj[parent].append(i)
|
||||
in_deg[i] += 1
|
||||
queue = []
|
||||
for i in range(1, n + 1):
|
||||
if in_deg[i] == 0:
|
||||
heapq.heappush(queue, i)
|
||||
ans = []
|
||||
while queue:
|
||||
cur = heapq.heappop(queue)
|
||||
ans.append(cur)
|
||||
for nb in adj[cur]:
|
||||
in_deg[nb] -= 1
|
||||
if in_deg[nb] == 0:
|
||||
heapq.heappush(queue, nb)
|
||||
print(*(ans))
|
||||
Loading…
Add table
Add a link
Reference in a new issue