CF-2087I•Codeforces

Hamiltonian Partition

*special

You are given a directed acyclic graph with nn vertices and mm edges. The graph contains no cycles or multiple edges.

You need to partition all the edges of this graph into Hamiltonian cycles (cycles that visit each of the nn vertices of the graph exactly once) such that each edge belongs to exactly one cycle. It is obvious that this is impossible for the original graph, so before partitioning, you must add the minimum number of edges to the graph so that such a partition exists.

After adding edges, the graph may contain cycles and/or multiple edges, but it should still not have any self-loops.

Input

The first line contains two integers nn and mm (2≤n≤1002 \le n \le 100; 1≤m≤n(n−1)21 \le m \le \frac{n(n-1)}{2}).

The next mm lines contain two integers xix_i and yiy_i in the ii-th line (1≤xi,yi≤n1 \le x_i, y_i \le n; xi≠yix_i \ne y_i), representing a directed edge from vertex xix_i to vertex yiy_i.

Additional constraints on the input:

  • the given graph has no cycles or multiple edges.

Output

In the first line, output a single integer kk (1≤k≤n⋅m1 \le k \le n \cdot m) — the number of edges you add.

Then output kk lines, in the ii-th of which there should be two integers xix_i and yiy_i (1≤xi,yi≤n1 \le x_i, y_i \le n; xi≠yix_i \ne y_i), denoting the start and end of the next edge.

Then in a single line, output a single integer cc (1≤c≤m1 \le c \le m) — the number of Hamiltonian cycles into which you partition all the edges of the graph.

In the last line, output m+km+k integers a1,a2,…,am+ka_1, a_2, \dots, a_{m+k} (1≤ai≤c1 \le a_i \le c), where aia_i is the Hamiltonian cycle to which you assign the ii-th edge (the edges of the original graph are numbered from 11 to mm, and the new ones are from m+1m+1 to m+km+k).

If there are multiple answers that minimize the number of added edges, output any of them.

Sample 1
Input
3 2
1 2
2 3
Output
1
3 1
1
1 1 1
Sample 2
Input
5 4
1 2
3 2
3 4
5 4
Output
6
2 3
4 5
5 1
1 5
2 1
4 3
2
1 2 1 2 1 1 1 2 2 2
Sample 3
Input
4 6
1 2
2 4
4 3
1 3
2 3
1 4
Output
6
3 1
4 2
3 1
3 2
2 4
4 1
3
1 1 1 3 2 2 1 2 2 3 3 3

Discussions & Comments

Share your approach or ask questions about this problem (0)

You must be logged in to comment or start a discussion on this problem.

Log In

No comments yet. Be the first to comment!

Actions

Open on Codeforces

About Platform

CO
Codeforces
External Judge

Problem Discussions

0

Have questions or want to share your solution approach? Join the discussion.

View / write comments