#P3535. [POI 2012] TOU-Tour de Byteotia

[POI 2012] TOU-Tour de Byteotia

Description

Translated from POI 2012 Stage 2. Day 0 「Tour de Byteotia」.

Given an undirected graph with nn vertices and mm edges, find the minimum number of edges to delete so that all vertices with indices less than or equal to kk are not on any simple cycle.

Input Format

The first line contains three integers nn, mm, and kk, denoting nn vertices, mm edges, and kk as defined above.

Then follow mm lines, each containing two integers uu and vv, representing an undirected edge between uu and vv. It is guaranteed that there are no multiple edges.

Output Format

The first line contains an integer cntcnt, the minimum number of edges to delete.

Then output cntcnt lines, each containing two positive integers aa and bb, indicating that the edge between aa and bb is deleted. Output the smaller vertex first, then the larger one.

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

Hint

The sample illustration is as follows.

For 40%40\% of the testdata, n1000n \le 1000, m5000m \le 5000.

For 100%100\% of the testdata, 1n1061 \le n \le 10^6, 0m2×1060 \le m \le 2\times10^6, 1kn1 \le k \le n, 1u<vn1 \le u \lt v \le n.

Translated from LibreOJ.

Translated by ChatGPT 5