#P5830. [ZJOI2016] 随机树生成器

[ZJOI2016] 随机树生成器

Description

Xiao Y recently got a random number generator (random number generator). Xiao Y wants to use this random number generator to generate a tree with nn nodes. A tree is an undirected connected graph with no cycles.

After some research, Xiao Y found 44 random tree generation methods.

The first method is: first generate a uniformly random permutation p1,p2,,pnp_1,p_2,\ldots,p_n of 11 to nn. Then for every node ii (2in)(2 \leq i \leq n), add an edge from pip_i to pjp_j, where jj is a random integer from 11 to i1i-1.

The second method is: first generate a uniformly random permutation p1,p2,,pnp_1,p_2,\ldots,p_n of 11 to nn. Then for every node ii (2in)(2 \leq i \leq n), add an edge from pip_i to pjp_j, where jj is a random integer from i2\lfloor \frac {i}{2} \rfloor to i1i-1.

The third method is: first start with a graph of nn vertices with no edges. Then repeatedly generate a pair of vertices u,vu,v uniformly at random. If uu and vv are not connected in the current graph, add the edge (u,v)(u,v) to the graph. Repeat this process until the graph becomes connected.

The fourth method is: among all different labeled trees on nn vertices, choose one uniformly at random. Two trees are different if and only if there exists an edge (u,v)(u,v) that appears in exactly one of them. For example, (1,2),(1,3)(1,2),(1,3) and (1,2),(2,3)(1,2),(2,3) are two different trees.

Xiao Y generated many trees with nn nodes using these four methods, but she forgot which method generated each tree. Can you help her identify which random method generated each tree?

In this problem, let n=1000n=1000, meaning every tree generated by Xiao Y has 10001000 nodes.

Input Format

The first line contains 11 positive integer TT, indicating the TT-th set of testdata.

Then an integer mm, indicating there are mm trees.

For each tree, there are n1n-1 lines. Each line contains 22 positive integers u,vu,v, indicating there is an edge between node uu and node vv in this tree.

Output Format

Output a total of mm lines. Each line contains a positive integer from 11 to 44, indicating the random generation method of the corresponding tree.

见附件
见附件

Hint

For all testdata, it is guaranteed that the input trees are generated by the four methods above.

Each test point satisfies the following rules.

Test Point mm Rule
1 =2000=2000 Only methods 1,21,2 will appear.
2 =3000=3000 Only methods 1,2,31,2,3 will appear.
3 Only methods 1,3,41,3,4 will appear.
4 =4000=4000 None.
5

For each test point, it is guaranteed that each possible appearing generation method appears exactly 10001000 times.

Scoring

For each test point, there are 1010 scoring parameters a10,a9,a8,,a1a_{10},a_9,a_8,\ldots,a_1.

If the number of wrong answers in your output is xx, then you will get a score of 2s2s, where ss is the largest integer satisfying xasx \leq a_s. If x>a1x>a_1, then you will get 00 points.

If the output format is abnormal, you will also get 00 points. Please make sure your output has exactly mm lines, and each line is an integer from 11 to 44.

For the specific scoring parameters of each test point, see scores in the additional files.

Translated by ChatGPT 5