ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 6543 |
문제명 | 그래프의 싱크 |
레벨 | 플래티넘 4 |
분류 |
SCC |
시간복잡도 | O(V+E) |
인풋사이즈 | V<=5000, E<=100000 |
사용한 언어 | Python |
제출기록 | 35176KB / 172ms |
최고기록 | 172ms |
해결날짜 | 2022/10/14 |
"""Solution code for "BOJ 6543. 그래프의 싱크".
- Problem link: https://www.acmicpc.net/problem/6543
- Solution link: http://www.teferi.net/ps/problems/boj/6543
Tags: [SCC]
"""
from teflib import graph as tgraph
def main():
while (line := input()) != '0':
n, m = [int(x) for x in line.split()] # pylint: disable=unused-variable
graph = [[] for _ in range(n)]
edges = [int(x) for x in input().split()]
for v, w in zip(edges[::2], edges[1::2]):
graph[v - 1].append(w - 1)
con_graph, scc = tgraph.condensation_graph(graph)
answer = []
for successor_u, scc_u in zip(con_graph, scc):
if not successor_u:
answer.extend(scc_u)
print(*(u + 1 for u in sorted(answer)))
if __name__ == '__main__':
main()