위상정렬2 [백준] 2623번 - 음악프로그램 (파이썬) # 음악프로그램 import sys input = sys.stdin.readline N, M = map(int, input().split()) front = [0] * (N+1) arr = [[] for _ in range(N+1)] for i in range(1, M+1): temp = list(map(int, input().split())) for j in range(1, temp[0]): arr[temp[j]].append(temp[j+1]) front[temp[j+1]] += 1 result = [] for _ in range(N): for i in range(1, N+1): if front[i] == 0 and i not in result: result.append(i) for j in rang.. 2022. 2. 4. [백준] 2252번 - 줄 세우기 (파이썬) # 줄 세우기 from collections import deque import sys input = sys.stdin.readline N, M = map(int, input().split()) arr = [[] for _ in range(N+1)] front = [0] * (N+1) for _ in range(M): a, b = map(int, input().split()) arr[a].append(b) front[b] += 1 def sort(): result = [] q = deque() for k in range(1, len(front)): if front[k] == 0: q.append(k) while q: now = q.popleft() result.append(now) for nnow in .. 2022. 1. 24. 이전 1 다음