백준 2252 - 줄 세우기 파이썬 풀이 입니다
위상 정렬
위 문제는 순서가 정해져 있는 작업을 차례로 처리한다는 점에서
위상 정렬을 이용해서 풀이를 할 수 있다 

위와 같이 진입 차수를 구하여 위상정렬을 구현할 수 있는데 구현 순서는 다음과 같다
코드
from collections import deque 
from collections import defaultdict
def solution():
    N, M = map(int, input().split())
    queue = deque([])
    cnt = defaultdict(int)
    connect = defaultdict(list)
    for _ in range(M):
        A, B = map(int, input().split())
        cnt[B] += 1
        connect[A].append(B)
    for i in range(1, N + 1):
        if cnt[i] == 0:
            queue.append(i)
    
    answer = []
    while queue:
        node = queue.popleft()
        answer.append(node)
        for next in connect[node]:
            cnt[next] -= 1
            if cnt[next] == 0:
                queue.append(next)
    print(' '.join(map(str, answer)))
solution()
특이한 점은 이 문제는 답이 여러개가 될 수 있는데 크게 조건을 주지 않아 아무렇게나 출력해도 된다는 점이었다(개꿀~)

아싸 티어 상승
실버를 지나 골드를 넘어 언젠가 플레로 갈거야~