Under construction

Still being built. Things may change

Ants

Time limit5sMemory limit256 MB

Summary
On a weighted tree, for each ant, find the largest number of other ants it meets at one point in time, either inside a tunnel or at an anthill.
Level

Hard9 of 10

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

Problem

In the Hundred Byte Wood, the ants have built nn anthills numbered 11 through nn. The anthills are connected by two-way tunnels so that there is exactly one simple path between each pair of anthills.

Spring has come, and the queen ant announced an annual rotation of the anthill structure. The rotation involves mm worker ants. The ii-th ant must leave its anthill aia_i at time tit_i and travel to anthill bib_i along the shortest path. All ants move at the same speed, and none of them stops before reaching its destination.

The queen suspects that too many ants meeting at one point could start a secession. For each worker ant, find the largest number of other travelling ants that this worker meets at a single point, either inside a tunnel or at an anthill. Meetings happen only during travel. If the ii-th ant arrives at its destination at time ti′t_i', then ants ii and jj can meet only at a time tt in [ti,ti′]∩[tj,tj′][t_i, t_i'] \cap [t_j, t_j'].

Input

The first line contains two integers nn and mm (1≤n,m≤100 0001 \le n, m \le 100\,000), the number of anthills and the number of worker ants.

Each of the next n−1n - 1 lines contains three integers uiu_i, viv_i, did_i (1≤ui,vi≤n1 \le u_i, v_i \le n, ui≠viu_i \ne v_i, 1≤di≤1091 \le d_i \le 10^9). This means anthills uiu_i and viv_i are connected by a two-way tunnel, and a worker needs did_i time units to pass through it.

Each of the last mm lines contains three integers aia_i, bib_i, tit_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i, 1≤ti≤1091 \le t_i \le 10^9) describing a worker ant.

Output

Print mm lines. The kk-th line contains the largest number of travelling ants (other than ant kk) that ant kk meets at the same time.

Examples1

  1. Example 1

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