Solutions are presented as using the least memory and the fastest execution time. It also takes the top 10 most recent solutions from each language. If you want to limit to a specific index, click the "Solved" button and go to that problem.
ContestId |
Name |
Phase |
Frozen |
Duration (Seconds) |
Relative Time |
Start Time |
---|---|---|---|---|---|---|
1675 | Codeforces Round 787 (Div. 3) | FINISHED | False | 8100 | 80061899 | May 5, 2022, 2:35 p.m. |
Solved$ |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
---|---|---|---|---|---|---|
( 5383 ) | F | Vlad and Unfinished Business | PROGRAMMING | dfs and similar dp greedy trees |
B'Vlad and Nastya live in a city consisting of n houses and n-1 road. From each house, you can get to the other by moving only along the roads. That is, the city is a tree. Vlad lives in a house with index x , and Nastya lives in a house with index y . Vlad decided to visit Nastya. However, he remembered that he had postponed for later k things that he has to do before coming to Nastya. To do the i -th thing, he needs to come to the a_i -th house, things can be done in any order. In 1 minute, he can walk from one house to another if they are connected by a road. Vlad does not really like walking, so he is interested what is the minimum number of minutes he has to spend on the road to do all things and then come to Nastya. Houses a_1, a_2, ... , a_k he can visit in any order. He can visit any house multiple times (if he wants). The first line of input contains an integer t ( 1 <= t <= 10^4 ) -- the number of input test cases. There is an empty line before each test case. The first line of each test case contains two integers n and k ( 1 <= k <= n <= 2 cdot 10^5 ) -- the number of houses and things, respectively. The second line of each test case contains two integers x and y ( 1 <= x, y <= n ) -- indices of the houses where Vlad and Nastya live, respectively. The third line of each test case contains k integers a_1, a_2, ... , a_k ( 1 <= a_i <= n ) -- indices of houses Vlad need to come to do things. The following n-1 lines contain description of city, each line contains two integers v_j and u_j ( 1 <= u_j, v_j <= n ) -- indices of houses connected by road j . It is guaranteed that the sum of n for all cases does not exceed 2 cdot10^5 . Output t lines, each of which contains the answer to the corresponding test case of input. As an answer output single integer -- the minimum number of minut'... |
102550 |
No solutions yet.