#P2720. School Gift Points
School Gift Points
School Gift Points
Little A is going to school for an event where the school distributes gifts across many gift points. Each gift point has one-way roads to other gift points and offers a particular type of gift. To avoid receiving the same gift multiple times, these roads are one-way and there are no cycles. Moreover, for every road connecting points $a$ and $b$, if after removing this road there exists a vertex $c$ that can reach both $a$ and $b$, then that road will not be used in any valid path. Besides point $1$, every gift point has exactly one incoming road.
Little A is curious: Given a starting gift point $S$, among all gift points reachable from $S$ (including $S$ itself), how many different types of gifts can be collected?
inputFormat
The first line contains two integers $n$ and $S$ ($1 \le S \le n \le 10^5$), representing the total number of gift points and the starting gift point.
The second line contains $n$ integers, where the $i$-th integer indicates the type of gift at gift point $i$.
Each of the following $n-1$ lines contains two integers $u$ and $v$ ($1 \le u, v \le n$), representing a one-way road from gift point $u$ to gift point $v$. Note that, except for point 1, each point has exactly one incoming road.
outputFormat
Output a single integer: the number of distinct gift types among all gift points reachable from $S$.
sample
5 2
1 2 1 3 2
1 2
1 3
2 4
2 5
2