{"problem":{"name":"Ex - Ball Collector","description":{"content":"We have a tree with $N$ vertices. The $i$\\-th $(1 \\le i \\le N-1)$ edge is an undirected edge between vertices $U_i$ and $V_i$. Vertex $i$ $(1 \\le i \\le N)$ has a ball with $A_i$ written on it and anot","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc302_h"},"statements":[{"statement_type":"Markdown","content":"We have a tree with $N$ vertices. The $i$\\-th $(1 \\le i \\le N-1)$ edge is an undirected edge between vertices $U_i$ and $V_i$. Vertex $i$ $(1 \\le i \\le N)$ has a ball with $A_i$ written on it and another with $B_i$.\nFor each $v = 2,3,\\dots,N$, answer the following question. (Each query is independent.)\n\n*   Consider traveling from vertex $1$ to vertex $v$ on the shortest path. Every time you visit a vertex (including vertices $1$ and $v$), you pick up one ball placed there. Find the maximum number of distinct integers written on the picked-up balls.\n\n## Constraints\n\n*   $2 \\le N \\le 2 \\times 10^5$\n*   $1 \\le A_i,B_i \\le N$\n*   The given graph is a tree.\n*   All values in the input are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $B_1$\n$A_2$ $B_2$\n$\\vdots$\n$A_N$ $B_N$\n$U_1$ $V_1$\n$U_2$ $V_2$\n$\\vdots$\n$U_{N-1}$ $V_{N-1}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc302_h","tags":[],"sample_group":[["4\n1 2\n2 3\n3 1\n1 2\n1 2\n2 3\n3 4","2 3 3\n\nFor example, when $v=4$, you visit vertices $1,2,3$, and $4$. By choosing balls with $A_1,B_2,B_3,B_4(=1,3,1,2)$ written on them, the number of distinct integers on the balls is $3$, which is the maximum."],["10\n2 5\n2 2\n8 8\n4 3\n6 10\n8 1\n9 10\n1 7\n9 3\n5 10\n9 3\n1 9\n3 6\n4 1\n3 8\n10 9\n5 4\n7 2\n9 7","4 3 2 3 4 3 4 2 3"]],"created_at":"2026-03-03 11:01:13"}}