#P7054. [NWRRC 2015] Graph
[NWRRC 2015] Graph
题目描述
The sequence . . . , is called a permutation, if it contains every integer from to .
The permutation of vertices . . . , is a topological sort of a directed graph, if for every directed edge from to , vertex comes before in this permutation.
The permutation . . . , is lexicographically smaller than the permutation . . . , if there exists such that for every and
Given a directed acyclic graph, add at most directed edges to it in such a way, that the resulting graph still has no cycles and the lexicographically minimal topological sort of the graph is maximum possible.
输入格式
The first line of the input file contains three integers and -- the number of vertices and directed edges in the original graph, and the number of directed edges, that you are allowed to add ; .
Each of the following lines contains two integers describing directed edge from to .
The graph has no cycles.
输出格式
The first line of the output file should contain integers -- the lexicographically minimal topological sort of the modified graph. The second line should contain a single integer -- the number of directed edges to add. The following lines of the output should contain description of added directed edges in the same format as in the input file.
5 3 2
1 4
4 2
1 3
5 1 4 2 3
2
4 3
5 1
2 2 20
1 2
1 2
1 2
1
1 2
提示
Time limit: 2 s, Memory limit: 256 MB.