#P14623. [2018 KAIST RUN Fall] Coloring Roads

[2018 KAIST RUN Fall] Coloring Roads

题目描述

In RUN-land, there are nn cities numbered 11 to nn. Some pairs of cities are connected by a bidirectional road. It happens that there are n1n-1 roads in total and that for any two cities, and there is a unique path from one to the other.

The city number 11 is the capital. Initially all roads have no color. Alex, the king of RUN-land asks you to perform the following query QQ times.

  • u c m\tt{u\ c\ m}: Given a city uu, a color cc, and an integer mm, color all the roads on the unique path from uu to the capital in the color cc. Even if a road already has a color, change its color to cc. After coloring, compute the number of colors in which exactly mm roads are colored.

Given QQ queries in total, compute the answer for the second part of each query.

输入格式

The first line of the input contains three integers n,C,Qn,C,Q (1n,C,Q2×1051\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 n1n-1 lines contains two integers u,vu,v (1u,vn1\leq u,v\leq n) meaning that there is a bidirectional road directly connecting the cities numbered uu and vv.

Each of the next QQ lines contains a query, which contains 33 integers u,c,mu,c,m as described in the statement. (1un1\leq u\leq n, 1cC1\leq c\leq C, 0mn10\leq m\leq n-1)

输出格式

Print QQ lines, one for each query. Each line must contain one integer, the answer to the corresponding query.

6 5 5
1 3
2 3
1 4
6 3
5 2
5 1 3
6 2 2
2 3 1
4 4 1
1 5 0
1
2
2
3
1

提示

The answer for the last query is 11 since color 55 is used in 00 roads.