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

18071번 - Equidistant 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 512 MB148554847.059%

문제

In 2019 ICPC subregions structure was changed a little. Now for each subregion, we need to choose the best place for the subregion finals. To make things fair we want to choose a city in such a way that all teams will spend the same amount of time to get there.

To make things simpler we say that all teams will use trains to get to the finals. The railroad system can be represented as a tree where each city is a vertex and some pairs of cities are connected by a railroad. It takes exactly one hour to get from one city to another if they are directly connected.

You are given a description of the railroad system and the cities where teams are located. You need to choose any city that has an equal distance to all teams’ cities or detect that no such city exists.

입력

The first line of the input contains two integers n and m — the number of cities and the number of teams (1 ≤ m ≤ n ≤ 2 · 105). Each of the following n − 1 lines contains two integers vi and ui — the indices of the cities connected by the i-th railroad (1 ≤ vi, ui ≤ n). It is guaranteed that for each pair of cities there is exactly one simple path connecting them.

The next line contains m integers c1, c2, . . . , cm — the cities of the teams (1 ≤ ci ≤ n). All teams are located in different cities.

출력

If it is impossible to choose a city fairly, output a single word “NO”. Otherwise, output a the word “YES” at the first line. The second line should contain a single integer — the city where subregion finals should be held. If there is more than one solution, output any of them.

제한

예제 입력 1

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

예제 출력 1

YES
3

예제 입력 2

2 2
1 2
1 2

예제 출력 2

NO

힌트

출처

ICPC > Regionals > Northern Eurasia > Northwestern Russia Regional Contest > ICPC 2019-2020 North-Western Russia Regional Contest E번

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

출처

대학교 대회

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

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