Under construction

Still being built. Things may change

Metro

Time limit2.5sMemory limit1024 MB

Summary
Given a tree and a metro line on each station pair, for each station sum the even-indexed values of the sorted line numbers that pass through it.
Level

Medium7 of 10

Topics
Tree, DFS, Segment tree, Sorting
Solved
No attempts yet

Problem

In recent years the Compulsive Disorder Research Institute has become busy discovering and classifying all sorts of peculiar behaviors. You have been dispatched to investigate one such strange compulsion reported among ordinary metro travelers.

The underground metro has NN stations connected by N−1N-1 bidirectional paths, and MM metro lines with linear routes, each with a unique number. Each station has a display that shows the numbers of the metro lines passing through it in sorted order. One subject claims that whenever he sees a list of integers C0,C1,…,CLC_0, C_1, \ldots, C_L, he cannot resist computing the sum of the even-indexed terms S=C0+C2+C4+⋯+C2K+⋯S = C_0 + C_2 + C_4 + \cdots + C_{2K} + \cdots. Each display in the stations shows such a list.

Compute this sum for each of the NN displays.

Input

The first line contains two integers NN and MM. The next N−1N-1 lines each contain two integers xix_i and yiy_i, meaning there is a direct link between stations xix_i and yiy_i. The next MM lines each contain three integers aia_i, bib_i, and noino_i, meaning the metro line numbered noino_i goes from station aia_i to station bib_i.

Output

Output NN lines. Line ii must contain a single number, the sum for the display in station ii. If no metro passes through station ii, print 0 on line ii.

Constraints

1≤N≤200,0001 \le N \le 200{,}000, 1≤M≤200,0001 \le M \le 200{,}000, and 1≤noi≤M1 \le no_i \le M for all ii. All stations are reachable from each other.

Examples1

  1. Example 1

    Input
    6 4
    1 2
    2 4
    2 6
    1 3
    5 2
    5 6 3
    4 5 1
    4 3 2
    1 2 4
    
    Expected output
    2
    4
    2
    1
    1
    3