#P4581. [BJOI2014] 想法

[BJOI2014] 想法

Description

Xiao Qiang and Amiba are good friends. Xiao Qiang wants to prepare a set of problems.

His problems are known for broad scope (biased), deep probing (quirky), and high difficulty (hard). To prepare problems, he has collected MM essentially different ideas, and each idea forms a problem. However, he feels that using these problems to test contestants would make the contest too extreme, so he asks Amiba to help adjust his problems.

Amiba points out a general method called “combination” to make an exam’s coverage as comprehensive as possible. If two problems AA and BB are combined, then the set of ideas involved in the resulting problem is the union of the sets of ideas involved in AA and BB. Moreover, problems can be combined repeatedly.

For example, suppose Xiao Qiang currently has three ideas 1,2,31, 2, 3, corresponding to problems P1,P2,P3P_1, P_2, P_3 respectively:

  • Xiao Qiang combines P1P_1 and P2P_2 to get P4P_4. The set of ideas involved in P4P_4 is {1,2}\{1, 2\}.
  • Xiao Qiang combines P2P_2 and P3P_3 to get P5P_5. The set of ideas involved in P5P_5 is {2,3}\{2, 3\}.
  • Xiao Qiang combines P4P_4 and P5P_5 to get P6P_6. The set of ideas involved in P6P_6 is {1,2,3}\{1, 2, 3\}.

Now, Xiao Qiang tells you how each problem was formed by combination. Your task is to answer how large the set of ideas involved in each problem is.

However, this problem is hard. So you only need to answer fairly accurately with a relatively high probability.

Input Format

The first line contains two integers N,MN, M, denoting the number of Xiao Qiang’s problems and the number of ideas, respectively.
Then follow NMN - M lines, each containing two integers, indicating which two problems were combined to form each combined problem.
The MM ideas correspond to problems numbered 11 through MM. After that, the first combined problem is numbered M+1M + 1, the second combined problem is numbered M+2M + 2, and so on.

Output Format

This problem uses Special Judge.
Output NMN - M lines. Each line contains one integer, which is the number of ideas involved in each combined problem.

6 3
1 2
2 3
4 5
2
2
3

Hint

Constraints: For 100%100\% of the testdata, 1M1051 \le M \le 10^5, 1N1061 \le N \le 10^6.
If at least 95%95\% of your lines have absolute error within 25%25\% of the correct answers, you will receive points.
“Error within 25%25\%” means: if the correct answer is XX, then your answer falling in the closed interval [0.8X,1.25X][0.8X, 1.25X] counts as within 25%25\% error.

Translated by ChatGPT 5