[SWEA] 작업순서
Date:
[SWEA] 작업순서
Problem URL : 작업순서
for i in range(1, 11):
V, E = map(int, input().split())
edge = [[] for _ in range(V + 1)]
connect = [0] * (V + 1)
visited = [False] * (V + 1)
info = list(map(int, input().split()))
for j in range(E):
edge[info[2 * j]].append(info[2 * j + 1])
connect[info[2 * j + 1]] += 1
ans = []
q = []
for j in range(1, V + 1):
if connect[j] == 0:
q.append(j)
while q:
t = q.pop(0)
if not visited[t]:
visited[t] = True
ans.append(t)
for j in edge[t]:
connect[j] -= 1
if connect[j] == 0:
q.append(j)
print('#{} {}'.format(i, ' '.join(map(str, ans))))
Comments
간단한 BFS 문제
왜 D6인지 모르겠다…
댓글