Time Limit: 4000/2000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Check if there exists a path of length \(l\) in the given tree with weight assigned to each edges.

The first line contains two integers \(n\) and \(q\), which denote the number of nodes and queries, repectively.

The following \((n - 1)\) with three integers \(a_i, b_i, c_i\), which denote the edge between \(a_i\) and \(b_i\), with weight \(c_i\).

Note that the nodes are labled by \(1, 2, \ldots, n\).

The last line contains \(q\) integers \(l_1, l_2, \ldots, l_q\), denote the queries.

\((1 \leq n, q \leq 10^5, 1 \leq c_i \leq 2)\)

For each query, print the result in seperated line. If there exists path of given length, print "Yes". Otherwise, print "No".

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

Yes Yes Yes Yes No Yes

ftiasch