Under construction

Still being built. Things may change

Petrol stations

Time limit3.5sMemory limit2048 MB

Summary
Given a tree of N cities and a tank capacity K, count how many of the N^2 cars stop at each city's petrol station under the refuel-when-needed rule.
Level

Hard8 of 10

Topics
Tree, Divide and conquer, Sorting
Solved
No attempts yet

Problem

The Czech highway network consists of NN cities and N−1N-1 roads with known lengths in kilometers. There is exactly one path between each pair of cities. Each city has one petrol station, and there are no other petrol stations.

One day, several people went on a car trip. A total of N2N^2 cars traveled. For each ordered pair of cities (a,b)(a,b), exactly one car drove from city aa to city bb along the only path between them. Every car has the same fuel tank capacity of KK liters. A car consumes one liter of petrol per kilometer traveled. Before departure, each tank is full.

The Czechs are predictable and lazy. A car refuels only when it does not have enough petrol to reach the next city. It can still enter a city with an empty tank. When a car is forced to stop at a petrol station, it fills the tank completely.

The Czech tax authority wants to know how many cars stopped at each petrol station during the day. Using this predictable behavior, the count can be computed easily.

Input

The first line contains two space-separated integers NN and KK, the number of cities and the fuel tank capacity of each car. The next N−1N-1 lines describe the roads. Each line contains three space-separated integers uiu_i, viv_i, and lil_i, where uiu_i and viv_i are the cities connected by the ii-th road and lil_i is its length in kilometers. Cities are numbered from 00 to N−1N-1. It is guaranteed that there is exactly one path between every pair of cities.

Output

Output NN lines. The ii-th line (starting from city 00) contains the number of cars that stopped at the petrol station in city ii.

Constraints

  • 2≤N≤700002 \leq N \leq 70000
  • 1≤K≤1091 \leq K \leq 10^9
  • 0≤li≤K0 \leq l_i \leq K (for each ii such that 0≤i≤N−20 \leq i \leq N-2)

Examples2

  1. Example 1

    Input
    3 1
    0 1 1
    1 2 1
    
    Expected output
    0
    2
    0
    
  2. Example 2

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