Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(N+M-1):
    u, v = map(int, input().split())
    adjL[u-1].append(v-1)
    indegs[v-1] += 1

parents = [-1] * N
vRoot = [v for v in range(N) if indegs[v] == 0][0]
vNows = set([vRoot])
for _ in range(N+M):
    vNexts = set()
    for vNow in vNows:
        for v2 in adjL[vNow]:
            parents[v2] = vNow
            vNexts.add(v2)
    vNows = vNexts

for v in range(N):
    print(parents[v] + 1)


Fixed submission:
from collections import deque

N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(N+M-1):
    u, v = map(int, input().split())
    adjL[u-1].append(v-1)
    indegs[v-1] += 1

parents = [-1] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        parents[v2] = vNow
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)

for v in range(N):
    print(parents[v] + 1)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
adjL = [set() for v in range(N)]
indegs = [0] * N
for _ in range(N+M-1):
    u, v = map(int, input().split())
    adjL[u-1].add(v-1)
    indegs[v-1] += 1

parents = [-1] * N
v0s = [set() for v in range(N)] # 前回まで
vRoot = [v for v in range(N) if indegs[v] == 0][0]

vNows = set([vRoot])
while vNows:
    vNexts = set()
    v0News = [set() for v in range(N)] # 今回新しく
    for vNow in vNows:
        for v2 in adjL[vNow]:
            parents[v2] = vNow
            vNexts.add(v2)
            v0News[v2].add(vNow)
    vNows = vNexts

    for v in range(N):
        if not v0News[v]: continue
        for v0 in v0s[v]:
            adjL[v0].remove(v)
    for v in range(N):
        v0s[v] = v0News[v]

for v in range(N):
    print(parents[v] + 1)


Fixed submission:
from collections import deque

N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(N+M-1):
    u, v = map(int, input().split())
    adjL[u-1].append(v-1)
    indegs[v-1] += 1

parents = [-1] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        parents[v2] = vNow
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)

for v in range(N):
    print(parents[v] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(N+M-1):
    u, v = map(int, input().split())
    adjL[u-1].append(v-1)
    indegs[v-1] += 1

parents = [-1] * N
vRoot = [v for v in range(N) if indegs[v] == 0][0]
vNows = set([vRoot])
while vNows:
    vNexts = set()
    for vNow in vNows:
        for v2 in adjL[vNow]:
            parents[v2] = vNow
            vNexts.add(v2)
    vNows = vNexts

for v in range(N):
    print(parents[v] + 1)


Fixed submission:
from collections import deque

N, M = map(int, input().split())
adjL = [[] for v in range(N)]
indegs = [0] * N
for _ in range(N+M-1):
    u, v = map(int, input().split())
    adjL[u-1].append(v-1)
    indegs[v-1] += 1

parents = [-1] * N
Q = deque([v for v in range(N) if indegs[v] == 0])
while Q:
    vNow = Q.popleft()
    for v2 in adjL[vNow]:
        parents[v2] = vNow
        indegs[v2] -= 1
        if indegs[v2] == 0:
            Q.append(v2)

for v in range(N):
    print(parents[v] + 1)