Hamiltonian Partition
You are given a directed acyclic graph with vertices and 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 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 and (; ).
The next lines contain two integers and in the -th line (; ), representing a directed edge from vertex to vertex .
Additional constraints on the input:
- the given graph has no cycles or multiple edges.
Output
In the first line, output a single integer () — the number of edges you add.
Then output lines, in the -th of which there should be two integers and (; ), denoting the start and end of the next edge.
Then in a single line, output a single integer () — the number of Hamiltonian cycles into which you partition all the edges of the graph.
In the last line, output integers (), where is the Hamiltonian cycle to which you assign the -th edge (the edges of the original graph are numbered from to , and the new ones are from to ).
If there are multiple answers that minimize the number of added edges, output any of them.
3 2 1 2 2 3
1 3 1 1 1 1 1
5 4 1 2 3 2 3 4 5 4
6 2 3 4 5 5 1 1 5 2 1 4 3 2 1 2 1 2 1 1 1 2 2 2
4 6 1 2 2 4 4 3 1 3 2 3 1 4
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 InNo comments yet. Be the first to comment!
Actions
Open on CodeforcesAbout Platform
Problem Discussions
0Have questions or want to share your solution approach? Join the discussion.
View / write comments