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

21914번 - One Piece 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 256 MB31131244.444%

문제

The Goa Kingdom is a network of $n$ islands (identified by numbers from 1ドル$ to $n$), connected by $n - 1$ bidirectional bridges. The network is structured as a tree. Some islands contain valuable treasures, and Luffy is on a quest to find the treasures from all islands.

In order to ease the treasure hunting, he bought a detector from a local merchant. The detector should have shown the distance from each island to the closest treasure (in number of bridges); however, it seems to be horribly broken, and shows the distance from each island to the farthest treasure instead!

Nonetheless, he kept the distances that his broken detector showed for each of the islands, hoping that maybe not everything is lost. He now wonders which islands have a higher chance of containing a treasure.

Your task is to help Luffy by arranging the $n$ islands in order, from highest to lowest probability of containing a treasure, given that he now knows the distances shown by the detector for each of the $n$ islands. Initially, you can assume that each of the islands independently had a 50ドル\%$ chance of containing a treasure; in other words, every subset of islands was equally likely to be the subset of the treasure islands.

입력

The first line of the input contains $n$ (1ドル \le n \le 250,000円$), the number of islands. The following $n - 1$ lines describe the bridges. Each bridge connects two distinct islands. Finally, the last line contains $n$ non-negative integers, the distances (in number of bridges) shown on Luffy’s detector for each of the islands.

It is guaranteed that there is at least one non-empty subset that is consistent with the input data.

출력

Output a permutation of size $n,ドル the order of the islands from highest to lowest probability of containing a treasure. If two islands have the same probability of containing a treasure, output them in increasing order of their ids.

제한

예제 입력 1

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

예제 출력 1

3 4 5 1 2

예제 입력 2

4
2 1
3 2
3 4
1 0 1 2

예제 출력 2

2 1 3 4

힌트

In the first example, island 3ドル$ must contain a treasure, as it is the only one at distance 2ドル$ from island 2ドル$. Islands 4ドル$ and 5ドル$ have probability 2ドル/3$ each, while islands 1ドル$ and 2ドル$ have probability 1ドル/2$.

In the second example, the only possible scenario is that island 2ドル$ is the only one containing a treasure.

출처

ICPC > Regionals > Europe > Southeastern European Regional Contest > SEERC 2020 J번

Contest > Open Cup > 2020/2021 Season > Stage 17: Grand Prix of Southern Europe J번

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

출처

대학교 대회

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

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