Logo
(追記) (追記ここまで)

16181번 - Coloring Roads 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 1024 MB45515311132.362%

문제

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.

  • $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.

입력

The first line of the input contains three integers $n,\ C,\ Q$ (1ドル\leq n,\ C,\ Q\leq 200,000$), 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$)

출력

Print $Q$ 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 1ドル$ since color 5ドル$ is used in 0ドル$ roads.

힌트

출처

University > KAIST > KAIST ICPC Mock Competition > 2018 KAIST 8th ACM-ICPC Mock Competition A번

Contest > Open Cup > 2018/2019 Season > Stage 5: Grand Prix of Korea A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /