#P2764. 最小路径覆盖问题

    ID: 1769 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>网络流Special JudgeO2优化网络流 24 题

最小路径覆盖问题

Description

Given a directed graph G=(V,E)G=(V,E). Let PP be a set of simple paths (vertex-disjoint) in GG. If every vertex in VV appears in exactly one path in PP, then PP is a path cover of GG. Paths in PP can start at any vertex in VV, and their lengths are arbitrary; in particular, the length can be 00. The minimum path cover of GG is a path cover with the fewest number of paths. Design an efficient algorithm to find a minimum path cover of a DAG (directed acyclic graph) GG.

Input Format

The first line contains two positive integers nn and mm. Here nn is the number of vertices of the given DAG (directed acyclic graph) GG, and mm is the number of edges of GG. The next mm lines each contain two positive integers ii and jj, representing a directed edge (i,j)(i, j).

Output Format

Starting from the first line, output one path per line. The last line of the file is the minimum number of paths.

11 12
1 2
1 3
1 4
2 5
3 6
4 7
5 8
6 9
7 10
8 11
9 11
10 11
1 4 7 10 11
2 5 8
3 6 9
3

Hint

Constraints: For 100%100\% of the testdata, 1n1501 \leq n \leq 150, 1m60001 \leq m \leq 6000.

SPJ provided by @FlierKing.

Translated by ChatGPT 5