logo AlgoBeat OnlineJudge
登录 注册

#217725. [ICPC 2026 Wuhan I] Nailoong vs. Bombloong 2

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

This is a communication problem. In this problem, your program will be run twice. Between the two runs, all variables stored in memory will be lost, but the information obtained in the first run may be crucial for correctly solving the problem in the second run.

There are two characters in this problem: “Nailoong” and “Bombloong”.

Nailoong has the complete structural information of a tree with nodes, while Bombloong only knows the number of nodes . Since Bombloong has been imprisoned by the evil Little Leopard, Nailoong can only help Bombloong reconstruct a tree that is isomorphic to the original tree through a special one-way communication method.

The rules of communication are as follows:

  • Initially, all nodes in the tree are white.
  • Nailoong can perform operations (the value of is determined by Nailoong).
  • In the -th operation, Nailoong needs to choose a node on the tree and flip its color (white to black, black to white).
  • After each flip, let be the number of edges in the current tree whose two endpoints have different colors.
  • After operations, Nailoong obtains a sequence of length .

Nailoong cannot directly send node indices to Bombloong; she can only send the total number of operations and the sequence to Bombloong. After receiving , , and the sequence , Bombloong needs to construct and output a tree that is isomorphic to Nailoong's tree.

Communication Protocol

In each test case, the contestant's program will be run twice. A testing tool is provided in the handout files for local debugging.

First Run

In the first run, you will play the role of “Nailoong”.

Input

The first line of input contains an integer , which allows your program to identify that this is the first run.

The second line contains an integer (), representing the number of nodes in the tree.

The next lines each contain two integers (), representing an edge in the tree.

Output

The first line of output should contain an integer (), representing the number of operations.

The second line contains integers (), representing the indices of the nodes flipped by Nailoong in each operation in sequence.

Second Run

In the second run, you will play the role of “Bombloong”.

Input

The first line of input contains an integer , which allows your program to identify that this is the second run.

The second line contains two integers (, ), representing the number of nodes and the number of operations performed by Nailoong, respectively.

If , the third line contains integers (), representing the sequence generated by the judge based on Nailoong's operations; if , the third line does not exist.

Output

Output lines, each containing two integers , representing an edge of the tree you reconstructed (). You must ensure that the output tree is isomorphic to the tree provided in the input of the first run.

First Run

standard input

1
4
1 2
2 3
3 4

standard output

1
2

Second Run

standard input

2
4 1
2

standard output

1 3
3 2
2 4

数据范围与提示

The two samples demonstrate the two runs within the same test case.

Nailoong flipped node . At this point, the number of edges with different colored endpoints is , so .

Bombloong received the sequence . Since Bombloong and Nailoong share a deep connection, she immediately guessed the structure of the tree. Although the tree obtained by Bombloong differs from the tree Nailoong held in terms of node indexing, they are isomorphic, so it is still considered correct.