| ps | |
|---|---|
| 링크 | acmicpc.net/… | 
| 출처 | BOJ | 
| 문제 번호 | 2150 | 
| 문제명 | Strongly Connected Component | 
| 레벨 | 플래티넘 5 | 
| 분류 | 
 SCC  | 
	
| 시간복잡도 | O(E+VlogV) | 
| 인풋사이즈 | E<=100,000 | 
| 사용한 언어 | Python | 
| 제출기록 | 36116KB / 228ms | 
| 최고기록 | 180ms | 
| 해결날짜 | 2022/10/20 | 
"""Solution code for "BOJ 2150. Strongly Connected Component".
- Problem link: https://www.acmicpc.net/problem/2150
- Solution link: http://www.teferi.net/ps/problems/boj/2150
Tags: [SCC]
"""
import sys
from teflib import graph as tgraph
def main():
    V, E = [int(x) for x in sys.stdin.readline().split()]
    graph = [[] for _ in range(V)]
    for _ in range(E):
        A, B = [int(x) for x in sys.stdin.readline().split()]
        graph[A - 1].append(B - 1)
    sccs, _ = tgraph.strongly_connected_component(graph)
    for scc in sccs:
        scc.sort()
    print(len(sccs))
    for scc in sorted(sccs):
        print(*(u + 1 for u in scc), '-1')
if __name__ == '__main__':
    main()