Stifon owns plots of land cultivated with corn, connected by bidirectional roads, ensuring that it is possible to travel from one plot to another on exactly one path. Stifon can position himself on a plot numbered and select another plot , where and , and collect corn from the plots along the path from to . Note that for a plot , there can be multiple plots that satisfy the given conditions. Therefore, Stifon notes as the total sum of corn from each path where and .
Task
Help Stifon calculate the total sum if he starts harvesting from any plot, specifically the value mod .
Input data
The input contains:
- The first line contains two integers and .
- The second line contains an array with elements representing the amount of corn in each plot.
- The next lines contain two numbers and indicating there is a road between plots and .
Output data
The first line contains the required value, mod .
Constraints and clarifications
- .
- for .
- is the minimum number of roads on the path from D to W.
# | Score | Constraints |
---|---|---|
1 | 5 | |
2 | 10 | |
3 | 5 | |
4 | 10 | |
5 | 20 | |
6 | 10 | |
7 | 40 | No additional constraints |
Example 1
stdin
3 2
10 5 9
2 1
1 3
stdout
58
Explanation
For , we can choose with .
For , we can choose either or , .
.
Example 2
stdin
10 3
679062366 599100597 187934521 236893327 61406391 912961000 46426980 729873627 889249584 650085534
2 1
7 9
5 7
1 3
8 7
4 2
4 9
10 3
6 7
stdout
396699172
Explanation
You count them yourself!