Bipartite Graph
Time limit2sMemory limit1024 MB
Build a bipartite graph with d and d-2 vertices and at most 3d edges so that removing any two vertices from the first part still leaves a perfect matching.
- Level
Medium6 of 10
- Topics
- Graph, Implementation, Math
- Solved
- No attempts yet
Problem
In this problem, you have to construct a bipartite graph with the following properties:
- The number of vertices in the first part is .
- The number of vertices in the second part is .
- The number of edges is at most .
- For every bipartite graph obtained by removing two vertices from the first part, there is a perfect matching.
A bipartite graph has its vertices divided into two parts so that each edge connects a vertex from the first part with a vertex from the second part. A perfect matching is a set of edges such that every vertex of the graph is an endpoint of exactly one edge in the set.
Input
The first line contains an integer , the number of test cases (). Each of the next lines contains an integer , the number of vertices in the corresponding test case ().
Output
For each test case, print an integer , the number of edges, on its own line. Then print lines, each describing one edge as a pair of integers and : the numbers of the vertices in the first and second part connected by that edge (, ).
The graph must not contain multiple edges.
Hint
You do not need to minimize the number of edges.