Farthest City

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

요약
정점 n개와 간선 n개로 이루어진 연결 그래프에서 각 정점마다 가장 먼 정점까지의 최단 거리를 구한다.
난이도

어려움10점 중 8점

유형
그래프, 최단 경로, 트리, DFS
정답자
아직 제출이 없습니다

문제

There are nn cities in the State of Confusion, numbered from 11 to nn. There are nn bidirectional roads that connect the cities. The iith road connects cities a_ia\_i and b_ib\_i, and is d_id\_i miles long.

All nn 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 nn (3≤n≤3⋅1053 \le n \le 3 \cdot 10^5), representing the number of cities in the state. Each of the next nn lines contains three integers a_ia\_i, b_ib\_i, d_id\_i (1≤d_i≤1071 \le d\_i \le 10^7), describing one of the roads.

출력

Output nn integers on a single line, where the iith number denotes the distance of the city that is the farthest from city ii.

예제1

  1. 예제 1

    입력
    4
    1 2 1
    2 3 2
    3 4 3
    4 1 4
    
    예상 출력
    4 5 3 5