#P16344. [科大国创杯初中组 2026] 构造题
[科大国创杯初中组 2026] 构造题
Background
Subtask 0 uses community testdata, and Subtask 1 uses official testdata.
Problem Description
You need to construct a directed acyclic graph (DAG) with vertices and edges without multiple edges (vertices are numbered starting from ). The in-degree of vertex and the out-degree of vertex must both be . Also, for every integer in , it must be possible to keep only some directed edges in the graph so that the number of distinct paths from vertex to vertex is exactly . Please output the DAG you constructed, and for each , specify which edges need to be kept.
The answer is not unique, so you only need to output any feasible solution. See the output format for details. You may choose the values of and yourself, but you must ensure .
A path from vertex to vertex that passes through vertices can be described as a sequence of length , , where , and for , the graph contains a directed edge .
Two paths are different if and only if , or there exists a positive integer in such that .
Input Format
The input contains only one line with a positive integer .
Output Format
- On the first line, output two positive integers , representing the number of vertices and edges in the DAG you construct.
- On the next lines, on the -th line output two positive integers , representing the -th directed edge in the graph.
- On the next lines, on the -th line output a string of length consisting only of
0and1, indicating which edges to keep in order to make the number of distinct paths from vertex to vertex equal to . From left to right, the -th character is1if the -th edge is kept, and0otherwise.
3
5 6
1 2
2 5
1 3
3 5
1 4
4 5
000000
110000
111100
111111
Hint
Sample Explanation
In the sample, . The figure on the next page shows a feasible graph constructed by the sample output.

When none of the six edges are selected, vertex obviously cannot reach vertex , so the number of paths is .
When only edges and are kept, there is only one path from vertex to vertex (), so the number of paths is .
When edges are kept, there are two paths from vertex to vertex ( and ), so the number of paths is .
When all edges are kept, there are three paths from vertex to vertex ( and ), so the number of paths is .
Therefore, this construction is valid.
Constraints
For all testdata, it is guaranteed that .
This problem has a total of twenty test points. For each test point, the input is known (see the table below). You will get the score for a test point only if your construction is valid and satisfies . Otherwise, you will get no score for that test point.
| Test Point ID | Test Point ID | Test Point ID | Test Point ID | ||||
|---|---|---|---|---|---|---|---|
Friendly Reminder
-
When is large, the output size is large, so please use a proper way to output. You should also open the output file properly to prevent your computer from crashing.
-
A checker
checker.cppis provided for you to test whether your construction is valid. The provided checker is different from the one used in the final judging, and you do not need to care about its internal details. Please extract the file provided with this problem. -
Extract
checker.cppto the folder where your program for this problem is located. Then right-click in that folder, choose “Open in Terminal”, and compilechecker.cppusing the following command:g++ checker.cpp -o checker -O2 -std=c++14 -
Then test your output using the following command:
./checker construct.in construct.out -
After the command runs successfully, if your construction is valid, you will see
Accepted. Otherwise, you will seeWrong answerand detailed error information.
Translated by ChatGPT 5