#P6219. [COCI 2019/2020 #6] Konstrukcija
[COCI 2019/2020 #6] Konstrukcija
Description
Translated from COCI 2019/2020 Contest #6 T3. Konstrukcija
Let be a directed acyclic graph. If distinct vertices in satisfy that there is a path from to , a path from to , ..., and a path from to , then the array is called an ordered array that starts at and ends at .
Note that for any two adjacent elements in , there does not have to be a direct edge between them; having a path is enough.
We also define the length of an ordered array as . Therefore, the length of an ordered array is exactly the number of vertices it contains.
Note that an ordered array of length that starts and ends at the same vertex can exist.
Moreover, we define the sign of an ordered array as .
For vertices in , let denote the set of all ordered arrays that start at and end at .
Finally, we define the contradiction value between vertices as $\mathrm{tns}(x,y) = \sum\limits_{C \in S_{x,y}} \mathrm{sgn}(C)$.
That is, the contradiction value between and equals the sum of the signs of all ordered arrays that start at and end at .
Given an integer , you need to construct a directed acyclic graph with at most vertices and edges such that , where is the number of vertices.
Vertices are numbered by positive integers .
Input Format
The first line contains one integer 。
Output Format
The first line contains two integers , the number of vertices and edges in the directed acyclic graph you construct.
In the next lines, the -th line contains two distinct integers , meaning the -th edge is directed from to . Each edge should appear at most once.
Also, your construction must satisfy that for any two vertices, the absolute value of their contradiction value is at most .
If there are multiple solutions, output any one of them.
0
6 6
1 4
1 5
4 3
5 3
3 2
2 6
1
1 0
2
6 8
1 2
1 3
1 4
1 5
5 4
2 6
3 6
4 6
Hint
Explanation for Sample 1
The constructed graph has vertices. The ordered arrays that start at and end at are:
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- ;
- 。
Their lengths are , respectively,
so their signs are , respectively.
Therefore, the contradiction value between and is 。

Constraints
For of the testdata, .
The limits for each subtask are shown in the table below:
| Subtask | Points | Limits |
|---|---|---|
| Sample only | ||
| - | ||
Translated by ChatGPT 5
京公网安备 11011102002149号