QOJ.ac

QOJ

Süre Sınırı: 2.0 s Bellek Sınırı: 1024 MB Toplam puan: 100

#17417. Alice and Bob

İstatistikler

Alice and Bob have a tree $T$ consisting of $2N$ nodes numbered from $1$ to $2N$.

Bob has an integer $K$, and wants to find $N$ pairs $(X_1, Y_1), (X_2, Y_2), \dots, (X_N, Y_N)$ such that each integer from $1$ to $2N$ appears in exactly one pair and the sum of distances $\sum_{i=1}^N \text{dist}(X_i, Y_i) = K$, where $\text{dist}(X_i, Y_i)$ denotes the distance between nodes $X_i$ and $Y_i$ in the tree, i.e. the number of edges on the (unique) path between $X_i$ and $Y_i$.

Alice doesn't want Bob to succeed. She can perform the following operation:

  • Remove an edge $(U, V)$ from $T$.
  • Add a new edge $(A, B)$ such that $T$ remains a tree.

Note that it is allowed to choose the same edge to both delete and insert, which will just result in the original tree.

Help Alice find an edge $(U, V)$ that should be deleted and an edge $(A, B)$ that should be added. If there are multiple solutions, you may find any of them.

It can be proven that under the constraints of this problem, it is always possible to delete an edge and add an edge such that there do not exist $N$ pairs $(X_1, Y_1), (X_2, Y_2), \dots, (X_N, Y_N)$ where each integer from $1$ to $2N$ appears in exactly one pair and the sum of distances equals $K$.

Input

The input is given in the following format:

$$T$$ $$N\ K$$ $$U_1\ V_1$$ $$U_2\ V_2$$ $$\vdots$$ $$U_{{2N-1}}\ V_{{2N-1}}$$ $$\vdots$$

  • All input values are integers.
  • $1 \le T \le 10^4$
  • $2 \le N \le 2 \times 10^5$
  • $1 \le K \le 10^{12}$
  • $1 \le U_i, V_i \le 2N$
  • It is guaranteed that the given edges form a tree.
  • It is guaranteed that the sum of $N$ over all test cases does not exceed $2 \times 10^5$.

Output

For each test case, output two lines:

The first line should contain two integers $U$ and $V$ — meaning that edge $(U, V)$ is to be deleted.

The second line should contain two integers $A$ and $B$ — meaning that edge $(A, B)$ is to be added.

If there are multiple solutions, print any of them.

Example

Input 1

2
2 20
1 2
2 3
3 4
2 4
1 2
2 3
3 4

Output 1

1 2
1 2
1 2
1 3

Note

Test case 1: The initial tree already has no way for Bob to obtain a score of $K = 20$, so Alice can simply remove and insert any existing edge.

Test case 2: The initial tree has a way for Bob to obtain a score of $K = 4$, for example by choosing pairs $(1, 4)$ and $(2, 3)$. Alice deletes edge $(1, 2)$ and inserts $(1, 3)$. In this new tree, Bob cannot obtain a score of $4$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.