#P7054. [NWRRC 2015] Graph

[NWRRC 2015] Graph

题目描述

The sequence a1,a2,a_{1}, a_{2}, . . . , ana_{n} is called a permutation, if it contains every integer from 11 to nn .

The permutation of vertices a1,a2,a_{1}, a_{2}, . . . , ana_{n} is a topological sort of a directed graph, if for every directed edge from uu to vv , vertex uu comes before vv in this permutation.

The permutation a1,a2,a_{1}, a_{2}, . . . , ana_{n} is lexicographically smaller than the permutation b1,b2,b_{1}, b_{2}, . . . , bn,b_{n}, if there exists mm such that ai=bia_{i} = b_{i} for every 1i<m1 \le i < m and am<bm.a_{m} < b_{m}.

Given a directed acyclic graph, add at most kk 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 n,mn , m and kk -- the number of vertices and directed edges in the original graph, and the number of directed edges, that you are allowed to add (1n100000(1 \le n \le 100 000 ; 0m,k100000)0 \le m , k \le 100 000) .

Each of the following mm lines contains two integers ui,vi,u_{i}, v_{i}, describing directed edge from uiu_{i} to vi(1ui,vin)v_{i} (1 \le u_{i}, v_{i} \le n) .

The graph has no cycles.

输出格式

The first line of the output file should contain nn integers -- the lexicographically minimal topological sort of the modified graph. The second line should contain a single integer x(0xk)x (0 \le x \le k) -- the number of directed edges to add. The following xx 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.