Logo
(追記) (追記ここまで)

30485번 - Journey of the Robber 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4.5 초 1024 MB149974465.672%

문제

Monopolis is a beautiful and wealthy country. Among its impressive features is the layout of the country, where N cities are interconnected by N − 1 roads of equal length, allowing to travel between any two cities.

Another unique feature of Monopolis is that each city has a single bank with a different amount of money. Thus, it is possible to assign a distinct number from 1 to N to each city, representing its wealth ranking relative to the other cities, with city 1 having the least money and city N having the most.

Rob is planning a “business trip” to Monopolis. Rob’s business is, in fact, robbing. Robbing banks, to be more precise. Rob is an ambitious robber and follows a particular modus operandi: he only targets banks with more money than the one he just robbed. Thus, after robbing in a city i, he moves to the closest city having more money. If there are multiple cities with more money than i at the same distance, he selects the one with the least money. If there’s no city richer than i, he remains in the same city and reflects on his actions.

Even though Rob is very set on his modus operandi, he is still planning his business trip to Monopolis, and then he asks for your assistance. Rob wants to know for each city i which would be the next city to visit in case his first heist is at city i.

입력

The first line contains an integer N (1 ≤ N ≤ 105) representing the number of cities in Monopolis. Each city is identified by a distinct integer from 1 to N, in increasing order of wealth.

Each of the next N − 1 lines contains two integers U and V (1 ≤ U, V ≤ N and U ≠ V), indicating that there is a two-way road between cities U and V . It is guaranteed that there is a path between each pair of cities using the given roads.

출력

Output a single line with N integers, such that the i-th of them indicates the next city Rob would visit in case his first heist is at city i.

제한

예제 입력 1

6
1 6
2 5
4 5
3 5
5 6

예제 출력 1

6 5 5 5 6 6

예제 입력 2

5
5 1
1 3
3 2
2 4

예제 출력 2

3 3 4 5 5

예제 입력 3

1

예제 출력 3

1

힌트

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2023 J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /