Codeforces Round 1092 (Unrated, Div. 2, Based on THUPC 2026 — Finals)
E
Oriented Journey
Codeforces
未评级
原题
← DF →
翻译中…

This is a run-twice (communication) interactive problem.

翻译中…

There are two players: Player A (Neri) and Player B (Mashiro). The jury will first interact with Player A. After Player A ends their interaction, the jury will interact with Player B. Note that Player A and Player B may not directly pass information to each other; both players are only able to send information to or receive information from the jury, but they may agree on the strategy they will use to communicate.

翻译中…

Before the interaction, the jury determines an undirected tree $T$ of size $n$ and an integer $s$ ($1\le s\le 2^{n-1}$). These values are consistent across both players.

翻译中…

Player A (Neri) first receives the two integers $n$ and $s$ from the jury without acquiring extra information about the tree $T$. Then, the jury will interact with Neri for exactly $n-1$ rounds. In each round of interaction:

翻译中…
  • The jury will reveal an undirected edge of $T$ to Neri, and then Neri needs to assign a direction to it immediately.
翻译中…

Note that all $n-1$ edges of $T$ are directed after this interaction, forming a new directed tree $T'$.

翻译中…

Player B (Mashiro) receives the directed tree $T'$ created in the interaction between Neri and the jury. Her task is to determine the value of $s$ according to the information she receives.

翻译中…

Neri wants to ensure that Mashiro can determine the integer $s$. Your task is to act as both players and determine an optimal interaction strategy for both players so that Mashiro can determine the integer $s$ correctly.

翻译中…

First Run

翻译中…

Your code will be run exactly two times on each test. On the first run, you will be Player A (Neri).

翻译中…

Input

翻译中…

The first line of the input contains two integers $t$ and $q$ ($1 \le t \le 10^4$, $q=1$) — the number of test cases and the run number. Here, the purpose of giving $q=1$ is so your program recognizes that this is its first run, and it should act as Player A (Neri).

翻译中…

For each test case, you should first read two integers $n$ and $s$ ($3\le n \le 30$, $1\le s \le 2^{n-1}$) — the size of $T$ and the integer to deliver.

翻译中…

Interaction

翻译中…

For each test case, recall that you will first receive $n$ and $s$ in the input from the jury according to the input format above. Then, you need to interact with the jury exactly $n-1$ times:

翻译中…
  • First, read two integers $u$ and $v$ ($1\le u \lt v\le n$) from the jury, denoting that there is an undirected edge $(u,v)$ in $T$;
  • Then, print two integers $a$ and $b$ on a new line to the jury, separated by a space, where $(a,b)$ is either $(u,v)$ or $(v,u)$. Printing $(a,b)=(u,v)$ means you assign the direction $u\rightarrow v$, and printing $(a,b)=(v,u)$ means you assign the direction $v\rightarrow u$.
翻译中…

Note that you must assign the direction for the current undirected edge before acquiring the information of the next one.

翻译中…

After that, you will either proceed to the next test case, or your program must terminate if you have processed every test case.

翻译中…

The interactor is not adaptive, which means that the tree $T$ in each test case is fixed before any interaction.

翻译中…

After each round of interaction do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict.

翻译中…

If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid interaction or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

翻译中…

Second Run

翻译中…

On the second run, you are Player B (Mashiro).

翻译中…

Input

翻译中…

The first line of the input contains two integers $t$ and $q$ ($1\le t\le 10^4$, $q=2$) — the number of test cases and the run number. Here, the purpose of giving $q=2$ is so your program recognizes that this is its second run, and it should act as Player B (Mashiro).

翻译中…

The first line of each test case contains a single integer $n$ ($3\le n \le 30$) — the size of $T'$.

翻译中…

Then $n-1$ lines follow, each containing two integers $u$ and $v$ ($1\le u,v\le n$), denoting that there is a directed edge $u\rightarrow v$ in $T'$.

翻译中…

Note that the test cases in the second run may be shuffled. Please see the example test case for further illustration.

翻译中…

Output

翻译中…

For each test case, output a single integer $s$ — the integer you determined from $T'$.

翻译中…

After this, do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded verdict. Then, proceed to the next test case, or terminate your program if it is the last test case.

翻译中…

Hacks

翻译中…

Hacks are not allowed in this problem.

翻译中…

$^{\text{∗}}$To flush, use: fflush(stdout) or cout.flush() in C++; sys.stdout.flush() in Python; see the documentation for other languages.

翻译中…

Note

翻译中…

For the first run: The integers $s$ delivered to Neri are $s=21$ and $s=59$, respectively. Then, according to some strategy agreed upon by the players, Neri directed the trees.

翻译中…

For the second run: Note that the test cases are re-ordered between runs. Here are the illustrations of $T'$ for both test cases in the order of the second run:

翻译中…

image Illustration for the first test case image Illustration for the second test case

翻译中…

Testing tool

翻译中…

You are provided with a command-line tool for local testing. You can download it from the materials.

翻译中…

To use the tool, you need to have Python installed. Run the command below in the terminal:

翻译中…
  • On Windows: python treedir_testing_tool.py [–quiet] <data_file> <program> <arguments>
  • On Linux: python3 treedir_testing_tool.py [–quiet] <data_file> <program> <arguments>
翻译中…

Arguments explanation:

翻译中…
  • -q, –quiet is an optional argument. The tool will print the interaction logs between itself and your program, and enabling this will make the tool stop printing them.
  • data_file is the input file you provide to the tool. It should follow the format below:
  • The first line contains two integers $t$ and $\text{seed}$, the number of test cases and the seed for shuffling the order of test cases/edges. Assigning $\text{seed}=0$ will make the tool keep the order without shuffling.
    • For each test case, the first line contains two integers $n$ and $s$. For the next $n-1$ lines, each line contains two integers $u$ and $v$, representing an edge in $T$.
  • program is the name of your compiled program.
  • arguments are the arguments your program needs.
翻译中…

The top line comments contain detailed information about the tool itself.

翻译中…

Note that:

翻译中…
  • This tool is not exactly the same as the interactor of the problem. Judge verdicts may differ.
  • This tool will check whether your input file follows the format, but it will not check whether your input satisfies the constraints.
  • This tool will not check if your program fits within the time/memory limit.
翻译中…

样例

Input #1
2 1
7 21
1 6
3 5
2 4
3 4
1 2
6 7
9 59
1 2
1 4
3 4
3 5
3 8
5 6
6 7
8 9
Output #1
6 1
3 5
4 2
3 4
1 2
7 6

1 2
1 4
3 4
3 5
8 3
5 6
6 7
9 8
InputCopy OutputCopy
Input #2
2 2
9
8 3
9 8
1 4
3 4
1 2
5 6
6 7
3 5
7
3 4
1 2
7 6
6 1
3 5
4 2
Output #2
59
21
InputCopy OutputCopy
题目信息
题号
2216E
时间限制
3 s
内存限制
256 MB

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