#P17382. [PacNW 2025] Farthest City

[PacNW 2025] Farthest City

Problem Description

The State of Confusion contains nn cities, numbered 11 through nn, and nn bidirectional roads. Road ii connects cities aia_i and bib_i and has length did_i miles.

All cities are connected. No road connects a city to itself, and there is at most one road between any pair of cities. The distance between two cities is the length of the shortest path connecting them.

For every city, find the distance to the city farthest from it.

Input Format

The first line contains an integer nn (3n31053\le n\le3\cdot10^5), the number of cities.

Each of the next nn lines contains three integers aia_i, bib_i, and did_i (1di1071\le d_i\le10^7), describing one road.

Output Format

Output nn integers on one line. The iith integer is the distance from city ii to its farthest city.

4
1 2 1
2 3 2
3 4 3
4 1 4
4 5 3 5