#abc302h. Ex - Ball Collector
Ex - Ball Collector
Score : points
问题描述
我们拥有一棵包含 个顶点的树。第 -条边(其中 )是从顶点 到顶点 的一条无向边。第 个顶点(其中 )上有一个写有数字 的球和另一个写有数字 的球。
对于每个顶点 ,独立回答以下问题:
- 考虑沿最短路径从顶点 行走到顶点 。每次访问一个顶点(包括顶点 和 ),你都会拾取该处放置的一个球。找出所拾取球上所写整数的最大不同数值数量。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a tree with vertices. The -th edge is an undirected edge between vertices and . Vertex has a ball with written on it and another with .
For each , answer the following question. (Each query is independent.)
- Consider traveling from vertex to vertex on the shortest path. Every time you visit a vertex (including vertices and ), you pick up one ball placed there. Find the maximum number of distinct integers written on the picked-up balls.
Constraints
- The given graph is a tree.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answers for , separated by spaces.
Sample Input 1
4
1 2
2 3
3 1
1 2
1 2
2 3
3 4
Sample Output 1
2 3 3
For example, when , you visit vertices , and . By choosing balls with written on them, the number of distinct integers on the balls is , which is the maximum.
Sample Input 2
10
2 5
2 2
8 8
4 3
6 10
8 1
9 10
1 7
9 3
5 10
9 3
1 9
3 6
4 1
3 8
10 9
5 4
7 2
9 7
Sample Output 2
4 3 2 3 4 3 4 2 3
update @ 2024/3/10 08:30:28