Tower Defense

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

The road network of Byteland kingdom consists of nn cities numbered from 11 to nn, connected with n1n-1 bidirectional roads. Each road has length 11. The road network is connected and its graph forms a tree.

There are mm military towers in the kingdom. The ii-th of them is situated in the city a_ia\_i and has region of protection with radius r_ir\_i. A city vv is protected by the tower ii if the travelling distance between vv and a_ia\_i doesn't exceed r_ir\_i.

King of Byteland is going to choose one of the cities as the new capital. The capital should be protected by all towers. The king can invest in extending protection of any existing tower. Increasing the radius of protection of any tower by any non-negative integer xx costs xk\lceil\frac{x}{k}\rceil coins. Find the smallest total amount of coins the king has to spend so that the capital protected by all towers can be chosen.

입력

The first line contains three integers n,m,kn, m, k (1n,m1051\leq n, m\leq 10^5, 1k101\leq k\leq 10) --- the number of cities, the number of towers, and the divisor for payment function respectively.

The next n1n-1 lines describe the roads. The ii-th of these contains three integers u_i,v_iu\_i, v\_i (1u_i,v_in1\leq u\_i, v\_i\leq n) --- indices of cities connected by the ii-th road. It is guaranteed that the given graph is a tree.

The next mm lines describe the towers. The ii-th of these lines contains two integers a_i,r_ia\_i, r\_i (1a_in1\leq a\_i\leq n, 0r_i1090\leq r\_i\leq 10^9) --- the index of the city where the ii-th tower is situated, and the radius of its protection.

출력

Print one integer --- the smallest amount of coins needed to spend on tower upgrades so that a new capital can be chosen.