A Dark Flame Dragon Sleeps in My Left Hand

For each node in a weighted tree, find the distance to the farthest other node (the tree's eccentricity).

Medium6TreeDFSDynamic programmingNo attempts yetTime limit2sMemory limit512 MB

Problem

Cheolsu keeps his left hand wrapped in bandages at all times. Unwrap them and the dark flame dragon breaks loose.

One day a typhoon hit the country where Cheolsu lives. The typhoon drove the dragon far past his control, so Cheolsu decided to leave on a long journey to calm it. Calming the dragon means getting as far away from the typhoon as he can, so he has to travel to the country farthest from the one he lives in.

Cheolsu's world consists of NN countries joined by N1N-1 roads. Each road connects two countries in both directions, and from any country there is a path to every other country. The distance between two countries is the sum of the lengths of the roads on that path.

When Cheolsu lives in country ii, let D[i]D[i] be the distance to the country his journey ends in. That is, D[i]D[i] is the largest distance from country ii to another country. Find D[i]D[i] for every ii with 1iN1 \le i \le N.

Input

The first line contains the number of countries NN (2N500002 \le N \le 50000).

Each of the next N1N-1 lines describes one road with three integers from, to, and length, meaning that a road of length length connects country from and country to. Both from and to are between 11 and NN and differ from each other, and length is an integer between 11 and 4000040000.

Output

Print NN lines. The ii-th line contains the value of D[i]D[i].