QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 250 MB 満点: 100

#7468. Chengdu No. 7 High School

統計

You are given a tree with $n$ nodes, where each node has a color. There are $m$ query operations.

Each query is given by parameters $l, r, x$. You need to output the number of distinct colors in the connected component containing $x$ when only nodes with indices in the range $[l, r]$ are kept.

Each query operation is independent.

Input

The first line contains two integers $n$ and $m$.

The second line contains $n$ integers representing the color of each node.

The next $n-1$ lines each contain two integers $x$ and $y$, representing an edge between $x$ and $y$.

The next $m$ lines each contain three integers $l, r, x$, representing a query operation.

Output

For each query, output a single integer representing the answer on a new line.

Examples

Input 1

5 4
1 3 5 3 5
1 2
2 3
3 4
4 5
1 5 1
2 4 3
3 4 3
1 4 3

Output 1

3
2
2
3

Note

Idea: nzhtl1477, Solution: nzhtl1477, Code: created_equal1, Data: nzhtl1477

For $100\%$ of the data, all colors are in the range $[1, 10^5]$, and it is guaranteed that $l \le x \le r$ for every query.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.