Topic Portal (internal title 12)
Input Format
The first line, a n-$ $ integer, the representative points of the tree.
Second row, n-$ $ integers, the first integer is the $ I $ $ $ B_i, described arrangement $ B $.
Next, $ n-1 $ lines of two integers $ u, v $, describe a tree edge $ (u, v) $.
Guarantee $ 1 \ leqslant B_i \ leqslant n $, $ 1 \ leqslant u \ neq v \ leqslant n $. To ensure that data is valid.
Output Format
Represents an integer output value answers ^ {10} $ 7 $ 9 + modulo.
Sample
Sample input 1:
5
2 1 3 5 4
1 2
2 3
2 4
4 5
Sample output 1:
3
Sample input 2:
6
6 4 5 3 2 1
1 2
2 3
3 4
4 5
5 6
Sample Output 2:
9
Data range and tips
Sample $ 1 $ explanation:
Meet the conditions of the number of columns $ A $ are:
• $ (1,2,3,4,5) $
• $ (1,2,4,5,3) $
• $ (2,1,3,4,5 ) $
data range:
For all the data, $ 1 \ leqslant n \ leqslant 300,000 $.
answer