#P12534. [XJTUPC 2025] 奥日

    ID: 12369 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2025Special JudgeO2优化树论构造高校校赛

[XJTUPC 2025] 奥日

Description

The Spirit Tree is the source of life on Nibel Mountain, with its roots flowing with light that maintains the ecological balance of the entire forest. The body of the ancient tree is composed of nn cores of light, which are interconnected by n1n−1 energy branches to form an acyclic tree structure. Between any two cores, there is a unique energy branch path winding between them, as if woven by the threads of fate.

Ori, originally the guardian spirit nurtured by the ancient tree, was swept into the abyss by a violent storm on a rainy night when thunder tore the sky apart. The ancient tree, having lost Ori, attempted to call him back through a light ritual, but the uncontrolled energy backlash plunged it into eternal night, and the once clear cores are now covered with dark patterns.

Now, the returning Ori must activate all the eroded cores: when he first touches a core, pure energy will dispel the darkness; however, upon repeated passes, chaotic energy will accumulate to form overload waves. The ancient tree's laws strictly limit that the total number of repeated triggered waves along the entire path must not exceed kk.

At this moment, Ori is suspended in the void woven by the star network. He can start from any core and traverse along the trajectories of the energy branches. Ori needs to plan a path among the winding energy branches to light up the maximum number of cores within the limits.

Only by resonating with as many light cores as possible can the true power of the ancient tree be awakened, allowing the healing light to surge again through every leaf vein of Nibel Mountain! Nibel Mountain will welcome dawn, and darkness will eventually be reduced to ashes in the resonance of this star network...

Formally, given a non-negative integer kk, provide an unrooted tree T=(V,E)T=(V,E), where V={1,2,,n}V=\{1,2,\dots,n\}.

Define a path l=(u1,u2,u3,,um)l=(u_1,u_2,u_3,\dots,u_m) composed of mm vertices such that for any 1im11\le i\le m-1, (ui,ui+1)E(u_i,u_{i+1})\in E. If there exists 1i<jm1\le i<j\le m such that ui=uju_i=u_j, the path ll is still considered valid.

Define the set of essential distinct points on path ll as V={vv=ui,i[1,m]}V'=\{v\mid v=u_i,\exists i\in [1, m]\}. Let V|V'| be the size of the set VV'. Let the number of repeated points on path ll be ss, where s=mVs=m-|V'|.

You need to find a path ll that maximizes V|V'| while satisfying sks\le k.

You need to output this path. If there are multiple paths that satisfy the conditions, output any one valid path, and it will be considered correct.

Input Format

The input contains multiple test cases. The first line of data contains an integer tt (1t2×1031 \leq t \leq 2\times 10^3) indicating the number of test cases. The following describes each test case.

The first line of each test case contains two integers nn (2n2×1052\le n\le 2\times 10^5) and kk (0kn0\le k\le n), separated by a space, representing the number of points on the tree and the maximum number of repeatable points. Note that kk can be 00.

The next n1n-1 lines each contain two positive integers uu and vv (1u,vn1\le u,v\le n), separated by a space, indicating that there is an edge (u,v)(u,v) on the tree. It is guaranteed that these n1n-1 edges form a tree.

It is guaranteed that the sum of nn for all test cases does not exceed 2×1052\times 10^5.

Output Format

For each test case, output two lines.

The first line contains a positive integer mm, indicating the number of vertices in path ll. The path ll must maximize the size of the essential distinct point set V|V'| while satisfying the number of repeated points sks\le k.

The second line contains mm positive integers u1,u2,u3,,umu_1, u_2, u_3, \dots, u_m, separated by spaces, indicating that the path ll is (u1,u2,u3,,um)(u_1, u_2, u_3, \dots, u_m).

If there are multiple paths that satisfy the conditions, output any one valid path, and it will be considered correct.

It can be proven that for a valid path, mm must satisfy mn+km\le n+k. The output mm must satisfy mn+km \le n+k, otherwise it will directly return Wrong Answer\tt{Wrong\ Answer}.

2
9 3
1 3
2 1
7 5
9 3
2 8
1 5
4 1
6 5
4 4
1 2
2 3
4 2
11
9 3 1 5 7 5 6 5 1 2 8
5
3 2 1 2 4

Hint

For the first test case, n=9n=9 and k=3k=3, the tree formed is as follows:

One feasible solution is: l=(9,3,1,5,7,5,6,5,1,2,8)l=(9,3,1,5,7,5,6,5,1,2,8). It can be proven that the size of the essential distinct point set V|V'| reaches the maximum value of 88, and the number of repeated points s=3ks=3\le k.

For the second test case, n=4n=4 and k=4k=4, the tree formed is as follows:

One feasible solution is: l=(3,2,1,2,4)l=(3,2,1,2,4). It can be proven that the size of the essential distinct point set V|V'| reaches the maximum value of 44, and the number of repeated points s=1ks=1\le k.

Due to the large input and output data size for this problem, it is recommended to use faster input and output methods.