Fire
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

lives on a tree with vertices. The vertices are labelled as and is in vertex . Each vertex has a temperature. On the morning of each day after day 0, the temperature of each vertex decreases by . The temperature doesn't decrease on day 0. On the afternoon of each day, can travel to an adjacent vertex, provided that he is at a vertex with positive temperature and his destination vertex has a non-negative temperature. On the evening of each day, if the temperature is higher than or equal to , can cast magic which increases the temperature of the vertex he is in by . For each pair of adjacent vertices and , can travel from vertex to vertex at most once (and from to at most once). He can choose not to travel and stay in the current vertex.

wants to cast his magic on each vertex exactly once. He also tries to stay at vertex as long as possible, before traveling to any other city. Given the temperature of each vertex right before the morning of the day , on which day must prepare for departing? If prepares on day , he can cast his magic on that day and will make his first move on day . If he cannot cast his magic on each vertex exactly once even if he prepares for departing on the day , output .

输入描述:

The first line contains two integers  and  ().
Each of the next lines contains two integers and , indicating an edge between vertices and ().
The (n+1)-th line contains n integers --- the temperature of vertex i right before the morning of day ().
It's guaranteed that the input is a tree structure.

输出描述:

If he cannot cast his magic on each vertex exactly once, output .
Otherwise, output a single integer --- he must prepare for departing from vertex on day . Day is the day after day , and so on.
示例1

输入

复制
3 1
1 2
1 3
4 3 5

输出

复制
1
示例2

输入

复制
3 1
1 2
1 3
2 10 10

输出

复制
-1