Petrol stations

시간 제한3.5초메모리 제한2048 MB

요약
트리 위 모든 순서쌍 도시 사이를 달리는 차가 다음 도시에 도달할 연료가 없을 때만 가득 주유한다고 할 때, 각 도시의 주유소에서 멈춘 차의 수를 구한다.
난이도

어려움10점 중 8점

유형
트리, 분할 정복, 그리디, DFS
정답자
아직 제출이 없습니다

문제

The Czech highway network consists of NN cities and N−1N-1 roads with known lengths in kilometers. We know that there exists exactly one path between each pair of cities. Furthermore, there exists exactly one petrol station in each of the cities and nowhere else.

One day, several people decided to go on a car trip. There were a total of N2N^2 cars traveling. Strangely, it holds that for each ordered pair of cities (a,b)(a,b) there was exactly one car going from the city aa to the city bb, traveling alongside the only path between these cities. Since everyone in Czechia uses Škoda cars, every car has the same fuel tank capacity of KK liters and they steadily consume one liter of petrol per kilometer traveled. Before departure, the fuel tank of each car is full. Furthermore, the Czechs are quite predictable. Due to their laziness, they refuel only when they don't have enough petrol to reach the next city (entering a city with an empty tank is still possible). Once they are forced to stop at a petrol station, they always fill their tank fully.

The Czech tax authority would like to know how many cars stopped at each petrol station during the day. Given this predictable behavior, you should be able to compute it easily.

입력

The first line of the input contains two space-separated integers NN and KK — the number of cities and the capacity of the fuel tank of each car. The following N−1N-1 lines describe roads. Each of them contains three space-separated integers u_iu\_i, v_iv\_i and l_il\_i, where u_iu\_i and v_iv\_i are indices of cities connected by the ii-th road and l_il\_i is the length of this road in kilometers. Cities are numbered from 00 to N−1N-1. It is guaranteed that for every pair of cities, there exists exactly one path between them.

출력

You should output NN lines, which should contain the number of cars stopping at the petrol station in each city, ordered from city 00 to city N−1N - 1.

제한

  • 2≤N≤70,0002 \leq N \leq 70\\,000
  • 1≤K≤1091 \leq K \leq 10^9
  • 0≤l_i≤K0 \leq l\_i \leq K (for each ii such that 0≤i≤N−20 \leq i \leq N-2)

예제2

  1. 예제 1

    입력
    3 1
    0 1 1
    1 2 1
    
    예상 출력
    0
    2
    0
    
  2. 예제 2

    입력
    6 2
    0 1 1
    1 2 1
    2 3 1
    3 4 2
    4 5 1
    
    예상 출력
    0
    3
    3
    12
    8
    0