German had always dreamed of joining the legendary tech company known as Infinite Compilation, Perpetual Confusion (ICPC). It was a company surrounded by mystery and challenge, where logic was king and only the brightest minds could find their place.
One day, German discovered something unusual about how the company worked. Every employee reported to exactly one other person, except for the CEO, who stood at the very top and had employee ID 1. From the CEO down, each person could have multiple people working under them, forming a giant organizational chart that branched out in every direction.
To join the company, German didn't need to submit a resume or pass a technical test. Instead, there was a unique challenge: he had to answer a series of questions about how the employees were organized and what they knew.
Each employee at ICPC was an expert in one specific topic. The questions German would face went something like this: "For a given employee x, how many people under their supervision—including themselves—know a specific topic k?"
His friend Sebastian, who had once tried to join ICPC, remembered these questions clearly. Before he was caught snooping through the company's systems, he managed to get a copy of the entire employee structure—who reports to whom—and the exact list of questions German would be asked.
Unfortunately, Sebastian was discovered before he could find and share the answers.
Now it's up to you to help German. With the structure and questions in hand, he just needs the correct answers so he can memorize them before his interview.
Will you help him prepare and finally enter the world of Infinite Compilation, Perpetual Confusion?
The first line of input contains two integers, $$$N$$$ $$$(1 \leq N \leq 100000)$$$ and $$$Q$$$ $$$(1 \leq Q \leq 100000)$$$ — the number of employees and the number of queries, respectively.
The second line contains $$$N$$$ integers $$$K_i$$$ $$$(1 \leq K_i \leq 10^9)$$$, where $$$K_i$$$ represents the topic known by employee $$$i$$$.
Each of the next $$$N-1$$$ lines contains two integers $$$X$$$ and $$$Y$$$ $$$(1 \leq X, Y \leq N,\ X \ne Y)$$$, meaning that employee $$$Y$$$ reports directly to employee $$$X$$$.
Each of the next $$$Q$$$ lines contains two integers $$$X$$$ and $$$k$$$ $$$(1 \leq X \leq N,\ 1 \leq k \leq 10^9)$$$, representing a question asking how many employees under the supervision of employee $$$X$$$ (including $$$X$$$) know topic $$$k$$$.
For every question, print a line with the correct answer.
7 41 1 2 3 4 1 11 21 32 42 53 63 73 12 42 31 1
2 1 1 4
| Name |
|---|


