Hamiltonian -vertex-connected Graph
Time limit1sMemory limit512 MB
Build a Hamiltonian graph on n vertices with vertex connectivity exactly k using the fewest edges, or report that none exists.
- Level
Medium7 of 10
- Topics
- Graph, Greedy, Implementation, Math
- Solved
- No attempts yet
Problem
A graph (other than a complete graph) has connectivity if is the size of the smallest subset of vertices such that the graph becomes disconnected if you delete them.
A connected undirected graph is called Hamiltonian if it has a Hamiltonian cycle: a cycle that visits each vertex exactly once (except for the vertex that is both the start and the end, which is visited twice).
Bobo would like to construct a Hamiltonian graph with vertices which has connectivity . Also, the number of edges in the graph should be minimum possible.
Input
The first line contains two integers and where is the number of vertices in the graph (, ).
Output
If there is no such graph, output on a single line. Otherwise, output an integer denoting the minimum number of edges. Then in each of the next lines, output two integers and (, ) denoting an edge in the graph. In the following line, output a permutation of integers denoting a Hamiltonian cycle in the graph.