- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
SBU Newbies Contest is the oldest annual contest in Computer Science and Engineering department. It is usually held on the second week of “Esfand”. There are many dedicated students who work voluntarily to prepare the contest. These students are divided into 3 groups and they take the tasks based on their group.
The first group of the students are the executive staff. They prepare the contest area, provide meals, do the registration, and many more things!! The second group of the students are the technical staff. They provide a secure network for the contest and setup the online judge. The last group is the scientific group. They write and prepare the problems, generate test cases, and verify the solutions.
This problem is written based on one of the challenges that technical staff faced during the preparation of the contest this year. As you may know, an official contest should strictly prohibit the use of internet during the contest. Trying to solve this problem, the technical staff should gather the cellphones before the contest or use mobile phone jammers in the contest area. Additionally, they should provide a network which restricts contestants’ internet access. After many hours of discussion and crowd-testing, they decided to configure a single router in the SBU and disconnect it from the internet.
The routers structure in the SBU network can be described as a rooted tree. Each router receives the internet from its parent router and will provide the internet for its children. When the technical team configure a router, all the routers in its subtree (including itself) would be disconnected from the internet, but the local connection is still available.
Given the routers which should be disconnected from internet and the structure of the SBU network, find the router which should be configured, in order to disconnect all the given routers from the internet.
If multiple answers exist, print the one which is the farthest from the root of the tree. We don’t want the whole university to lose internet access. You can assume that Router 1 is the root of the network.
ورودی
The first line of the input contains two space-separated integers $N$ and $K$ indicating the number of routers in the network and the number of routers which should be disconnected.
$$1 \leq N, K \leq 10^5$$
Each of the next $N - 1$ lines describe a connection by giving two space separated integers $u_i, v_i$ – the number of two routers operating as end-points of the connection.
The last line of the input contains $K$ space-separated distinc integer $a_i$ denoting the routers which should be disconnected from the internet.
$$1 \leq a_i, u_i, v_i \leq 10^5$$
خروجی
Print the lowest router which should be disconnected from the internet in order to avoid internet usage during the contest.
مثالها
ورودی نمونه ۱
7 2
1 2
2 7
3 4
2 4
4 5
6 4
6 7
خروجی نمونه ۱
2
ورودی نمونه ۲
4 1
1 3
2 3
2 4
3
خروجی نمونه ۲
3
ارسال پاسخ برای این سؤال