Farthest City
시간 제한3초메모리 제한2048 MB
정점 n개와 간선 n개로 이루어진 연결 그래프에서 각 정점마다 가장 먼 정점까지의 최단 거리를 구한다.
문제
There are cities in the State of Confusion, numbered from to . There are bidirectional roads that connect the cities. The th road connects cities and , and is miles long.
All cities are connected. In other words, regardless of which city you start from, it is always possible to reach any other city using the given roads. In addition, no road connects a city to itself, and there is at most one road between any pair of cities.
You are interested in holding a statewide event in one of the cities. One of the important factors to consider is how far away the rest of the cities are from where the event will be held. The distance between two cities is the length of the shortest path that connects them.
Given the information about all roads, find the distance to the farthest city from every city in the state.
입력
The first line of the input contains a single integer (), representing the number of cities in the state. Each of the next lines contains three integers , , (), describing one of the roads.
출력
Output integers on a single line, where the th number denotes the distance of the city that is the farthest from city .