| ps | |
|---|---|
| 링크 | acmicpc.net/… |
| 출처 | BOJ |
| 문제 번호 | 8314 |
| 문제명 | Acyclic Decomposition |
| 레벨 | 플래티넘 5 |
| 분류 |
DAG |
| 시간복잡도 | O(|E|) |
| 인풋사이즈 | |E|<100,000 |
| 사용한 언어 | Python 3.13 |
| 제출기록 | 64992KB / 216ms |
| 최고기록 | 196ms |
| 해결날짜 | 2026/02/14 |
"""Solution code for "BOJ 8314. Acyclic Decomposition".
- Problem link: https://www.acmicpc.net/problem/8314
- Solution link: http://www.teferi.net/ps/problems/boj/8314
Tags: [ad hoc]
"""
import sys
from teflib import graph as tgraph
def main():
n, m = [int(x) for x in sys.stdin.readline().split()]
edges = [
[int(x) - 1 for x in sys.stdin.readline().split()] for _ in range(m)
]
graph = [[] for _ in range(n)]
for u, v in edges:
graph[u].append(v)
if tgraph.is_acyclic(graph):
print('1')
print(m, *range(1, m + 1))
return
inc_order_edges, dec_order_edges = [], []
for i, (a, b) in enumerate(edges, start=1):
if a < b:
inc_order_edges.append(i)
else:
dec_order_edges.append(i)
print('2')
print(len(inc_order_edges), *inc_order_edges)
print(len(dec_order_edges), *dec_order_edges)
if __name__ == '__main__':
main()