#P14706. [ICPC 2023 Tehran R] Cup of Tea

[ICPC 2023 Tehran R] Cup of Tea

题目描述

Abolf lives in Aboland, a country consisting of nn cities and n1n-1 two-way roads. In Aboland, one can travel from any city to any other city using these roads. Aboland's cities are numbered from 1 to nn.

Abolbucks is a multinational chain of teahouses which serves the best tea in the world. When Abolf enters a city with an Abolbucks branch, he drinks a cup of tea and instantly reaches kk units of happiness. However, each time Abolf travels through the ithi^{th} road, he must pay cic_i coins as toll which causes him to lose cic_i units of happiness.

Abolf currently resides in city 1 and wants to plan his summer trip. If at any point during his trip Abolf's happiness drops below zero, he would stops his trip immediately. For each city tt (for 2tn2 \leq t \leq n), Abolf wants to know what is the minimum amount of coins he should pay to reach city tt while making sure that his happiness remains non-negative at all time, including at the destination. He has asked you to find this amount for each city except for his home city. Note that each destination should be considered separately. Also, he may visit a city multiple times during his trip.

输入格式

The first line of input contains two integers nn and kk (2n31052 \leq n \leq 3 \cdot 10^5, 1k1091 \leq k \leq 10^9), the number of cities in Aboland and Abolf's happiness after he drinks a cup of tea, respectively. Each of the next n1n-1 lines contains three space-separated integers viv_i, uiu_i, and cic_i (1vi,uin1 \leq v_i, u_i \leq n, 1ci1091 \leq c_i \leq 10^9, uiviu_i \neq v_i) indicating that the ithi^{th} road connects city uiu_i and city viv_i, and Abolf should pay cic_i coins each time he travels through this road. The last line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai10 \leq a_i \leq 1). If ai=1a_i = 1, there is an Abolbucks branch in city ii. It is guaranteed that a1=1a_1 = 1.

输出格式

In the only line of the output, you should print n1n-1 integers. The ithi^{th} number should be the minimum amount of coins it takes for Abolf to reach city i+1i+1 from city 1. If there is no way to reach city i+1i+1 such that Abolf's happiness remains non-negative at all time, print 1-1 for that city.

6 3
1 2 4
1 3 3
1 4 2
4 5 1
4 6 2
1 1 0 0 1 0
-1 3 2 3 6