Codeforces Round 290 (Div. 1)
E
Fox And Polygon
Codeforces
2900
原题
← D→
翻译中…

Fox Ciel just designed a puzzle game called "Polygon"! It is played using triangulations of a regular $*n*$-edge polygon. The goal is to transform one triangulation to another by some tricky rules.

翻译中…

image

翻译中…

Triangulation of an $*n*$-edge poylgon is a set of $*n* - 3$ diagonals satisfying the condition that no two diagonals share a common internal point.

翻译中…

For example, the initial state of the game may look like (a) in above figure. And your goal may look like (c). In each step you can choose a diagonal inside the polygon (but not the one of edges of the polygon) and flip this diagonal.

翻译中…

Suppose you are going to flip a diagonal $*a* – *b*$. There always exist two triangles sharing $*a* – *b*$ as a side, let's denote them as $*a* – *b* – *c*$ and $*a* – *b* – *d*$. As a result of this operation, the diagonal $*a* – *b*$ is replaced by a diagonal $*c* – *d*$. It can be easily proven that after flip operation resulting set of diagonals is still a triangulation of the polygon.

翻译中…

So in order to solve above case, you may first flip diagonal $6 – 3$, it will be replaced by diagonal $2 – 4$. Then you flip diagonal $6 – 4$ and get figure (c) as result.

翻译中…

Ciel just proved that for any starting and destination triangulations this game has a solution. She wants you to solve it in no more than $20 000$ steps for any puzzle satisfying $*n* ≤ 1000$.

翻译中…

Input

翻译中…

The first line contain an integer $*n*$ ($4 ≤ *n* ≤ 1000$), number of edges of the regular polygon.

翻译中…

Then follows two groups of $(*n* - 3)$ lines describing the original triangulation and goal triangulation.

翻译中…

Description of each triangulation consists of $(*n* - 3)$ lines. Each line contains 2 integers $*a*_{*i*}$ and $*b*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*$), describing a diagonal $*a*_{*i*} – *b*_{*i*}$.

翻译中…

It is guaranteed that both original and goal triangulations are correct (i. e. no two diagonals share a common internal point in both of these triangulations).

翻译中…

Output

翻译中…

First, output an integer $*k*$ ($0 ≤ *k* ≤ 20, 000$): number of steps.

翻译中…

Then output $*k*$ lines, each containing 2 integers $*a*_{*i*}$ and $*b*_{*i*}$: the endpoints of a diagonal you are going to flip at step $*i*$. You may output $*a*_{*i*}$ and $*b*_{*i*}$ in any order.

翻译中…

If there are several possible solutions, output any of them.

翻译中…

Note

翻译中…

Sample test 2 is discussed above and shown on the picture.

翻译中…

样例

Input #1
4
1 3
2 4
Output #1
1
1 3
InputCopy OutputCopy
Input #2
6
2 6
3 6
4 6
6 2
5 2
4 2
Output #2
2
6 3
6 4
InputCopy OutputCopy
Input #3
8
7 1
2 7
7 3
6 3
4 6
6 1
6 2
6 3
6 4
6 8
Output #3
3
7 3
7 2
7 1
InputCopy OutputCopy
题目信息
题号
512E
时间限制
2 s
内存限制
256 MB
标签
构造
分治

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。