logo AlgoBeat OnlineJudge
登录 注册

#206206. [NWRRC 2015] Graph

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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.

样例

样例输入 1

5 3 2
1 4
4 2
1 3

样例输出 1

5 1 4 2 3
2
4 3
5 1

样例输入 2

2 2 20
1 2
1 2

样例输出 2

1 2
1
1 2

数据范围与提示

Time limit: 2 s, Memory limit: 256 MB.