#P13941. [EC Final 2019] Fire

[EC Final 2019] Fire

题目描述

Pang\textit{Pang} lives on a tree with nn vertices. The vertices are labelled as 1,2,,n1,2,\ldots, n and Pang\textit{Pang} is in vertex 11. Each vertex has a temperature. On the morning of each day after day 0, the temperature of each vertex decreases by 11. The temperature doesn't decrease on day 0. On the afternoon of each day, Pang\textit{Pang} 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 00, Pang\textit{Pang} can cast magic which increases the temperature of the vertex he is in by kk. For each pair of adjacent vertices aa and bb, Pang\textit{Pang} can travel from vertex aa to vertex bb at most once (and from bb to aa at most once). He can choose not to travel and stay in the current vertex.

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

输入格式

The first line contains two integers nn and kk (2n100000,0k10000000002\le n\le 100000, 0\le k\le 1000000000).

Each of the next n1n-1 lines contains two integers xx and yy, indicating an edge between vertices xx and yy (1x,yn1\le x, y\le n).

The (n+1)(n+1)-th line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n --- the temperature of vertex ii right before the morning of day 11 (0ai10000000000\le a_i\le 1000000000).

It's guaranteed that the input is a tree structure.

输出格式

If he cannot cast his magic on each vertex exactly once, output 1-1.

Otherwise, output a single integer xx --- he must prepare for departing from vertex 11 on day xx. Day 11 is the day after day 00, and so on.

3 1
1 2
1 3
4 3 5
1
3 1
1 2
1 3
2 10 10
-1