P14623 [2018 KAIST RUN Fall] Coloring Roads
Description
In RUN-land, there are $n$ cities numbered $1$ to $n$. Some pairs of cities are connected by a bidirectional road. It happens that there are $n-1$ roads in total and that for any two cities, and there is a unique path from one to the other.
The city number $1$ is the capital. Initially all roads have no color. Alex, the king of RUN-land asks you to perform the following query $Q$ times.
- $\tt{u\ c\ m}$: Given a city $u$, a color $c$, and an integer $m$, color all the roads on the unique path from $u$ to the capital in the color $c$. Even if a road already has a color, change its color to $c$. After coloring, compute the number of colors in which exactly $m$ roads are colored.
Given $Q$ queries in total, compute the answer for the second part of each query.
Input Format
The first line of the input contains three integers $n,C,Q$ ($1\leq n,C,Q\leq 2\times 10^5$), separated by a single space, which are the number of cities in RUN-land, the number of possible colors, and the number of queries, respectively. Each of the next $n-1$ lines contains two integers $u,v$ ($1\leq u,v\leq n$) meaning that there is a bidirectional road directly connecting the cities numbered $u$ and $v$.
Each of the next $Q$ lines contains a query, which contains $3$ integers $u,c,m$ as described in the statement. ($1\leq u\leq n$, $1\leq c\leq C$, $0\leq m\leq n-1$)
Output Format
Print $Q$ lines, one for each query. Each line must contain one integer, the answer to the corresponding query.
Explanation/Hint
The answer for the last query is $1$ since color $5$ is used in $0$ roads.