Gourmet Tour

시간 제한0.5초메모리 제한1024 MB

요약
트리의 각 노드에 1부터 n까지의 순위를 배정해 모든 간선의 순위 차이 절댓값이 1부터 n-1까지 서로 다르게 만든다.
난이도

어려움10점 중 8점

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

문제

Minsu, who is attending university in Seoul, is planning a gourmet trip to Busan by train for the summer vacation. After researching all the restaurants along the way from Seoul to Busan, he finds that most of them are located in cities with stations on the Gyeongbu(GB) train line, and there are occasionally restaurants in cities a bit far from the GB train line stations. Minsu decides to visit the restaurants by getting off at the cities with stations while traveling from Seoul to Busan on the GB train line. In the case that a restaurant is in a city a bit far from a station on the GB train line, he plans to get off at the station, takes a taxi to the restaurant, visits it, and then returns to the station to catch the train again. Note that each city has one restaurant where he wants to visit. After successfully completing the trip, Minsu ranks the restaurants he has visited and discovers a curious fact. When he collects the values of the differences in the rankings of the restaurants that are in adjacent cities on his travel route, all the difference values are different. What can have been the rankings of the restaurants that Minsu gives?

Let us represent Minsu’s travel route in the form of a graph. The cities with stations on the GB train line or a bit far from that line where he visits restaurants are represented as nodes. Two nodes corresponding to consecutive cities on the GB train line are connected as an edge and two nodes corresponding to a city XX on the GB train line and a city YY a bit far from XX are also connected as an edge. When the total number of cities where Minsu visits restaurants is nn, the graph has nn nodes and n−1n - 1 edges. Nodes are numbered as distinct integers between 11 and nn. For example, the figure below represents Minsu's travel route in the form of an undirected graph with 1010 nodes (1010 restaurants in 1010 cities).

The rankings of restaurants assigned by Minsu are integers from 11 to nn without duplication. It can be considered as an assignment of rankings to nodes in the graph. The curious fact that Minsu discovers is that the differences of rankings assigned to any two adjacent nodes are all different. For example, the figure below represents the assigned rankings (blue numbers) and the differences (red numbers) of rankings between adjacent nodes. Note that the differences of rankings are integers from 11 to n−1n - 1 without duplication.

Given a travel route graph for nn cities, write a program to compute the rankings of nn restaurants in the cities satisfying the condition explained above.

입력

Your program is to read from standard input. The first line of input contains the integer nn (3≤n≤50,0003 ≤ n ≤ 50\\,000), representing the total number of nodes corresponding to the cities (restaurants) to be visited in the travel route graph. The nodes are numbered as 11 to nn. Each of the following n−1n - 1 lines contains two integers uu and vv (1≤u≠v≤n1 ≤ u \ne v ≤ n), separated by a space, representing an edge connecting two nodes uu and vv of the travel route graph.

출력

The first line should contain nn integers a_1,a_2,…,a_na\_1, a\_2, \dots , a\_n, separated by spaces, where a_ia\_i represents the ranking of city ii and must satisfy the condition mentioned above. Note that a_ia\_i is an integer between 11 and nn and there is no duplication among a_ia\_i’s. If there are multiple combinations of rankings that satisfy the condition, output any of them.

예제2

  1. 예제 1

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

    입력
    10
    1 3
    3 6
    6 7
    6 4
    6 5
    6 9
    9 8
    9 10
    9 2
    
    예상 출력
    3 7 4 8 9 2 6 5 10 1