logo AlgoBeat OnlineJudge
登录 注册

#214576. [2018 KAIST RUN Fall] Coloring Roads

内存限制:1024 MiB 时间限制:4000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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

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

  • : Given a city , a color , and an integer , color all the roads on the unique path from to the capital in the color . Even if a road already has a color, change its color to . After coloring, compute the number of colors in which exactly roads are colored.

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

输入格式

The first line of the input contains three integers (), 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 lines contains two integers () meaning that there is a bidirectional road directly connecting the cities numbered and .

Each of the next lines contains a query, which contains integers as described in the statement. (, , )

输出格式

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

样例

样例输入 1

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

1
2
2
3
1

数据范围与提示

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