#P9101. [PA 2020] Skierowany graf acykliczny
[PA 2020] Skierowany graf acykliczny
Problem Description
This problem is translated from PA 2020 Round 5 Skierowany graf acykliczny.
As the name suggests, a Directed Acyclic Graph (Directed Acyclic Graph, DAG for short) is a directed graph without cycles.
If we choose two nodes in such a graph, we can compute how many different directed paths exist between these nodes. If one path contains an edge and another path does not contain this edge, then we consider these two paths different.
Your task is to construct a directed acyclic graph with nodes (numbered from to ) such that there are exactly paths from node to node . Your graph can have at most nodes, each node can have at most two outgoing edges, and it cannot contain multiple edges (that is, if a node has two outgoing edges, they must go to different nodes). It can be proven that for every satisfying the constraints in the input, a valid graph can be constructed.
Input Format
One line with one integer .
Output Format
The first line prints one integer , which is the number of nodes in the graph you construct.
Then output lines, each with two integers. The -th line describes the destination node numbers of the outgoing edges starting from node . Either of these two numbers can be , meaning that this edge does not exist. If both numbers are not , then they must not be equal.
If there are many valid graphs, you may output any of them. Note that you do not need to minimize the number of nodes, and under the limits the number of nodes is sufficient.
3
6
3 5
6 -1
2 6
2 6
6 -1
-1 -1
Hint
Sample 1 Explanation
The figure below shows a directed acyclic graph with nodes from the output. There are three paths from to : , , and .

Constraints
This problem uses bundled testdata.
For of the testdata, it is guaranteed that and .
Translated by ChatGPT 5