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.
Problems
B'You have a tree with n vertices, some of which are marked. A tree is a connected undirected graph without cycles. Let f_i denote the maximum distance from vertex i to any of the marked vertices. Your task is to find the minimum value of f_i among all vertices. For example, in the tree shown in the example, vertices 2 , 6 , and 7 are marked. Then the array f(i) = [2, 3, 2, 4, 4, 3, 3] . The minimum f_i is for vertices 1 and 3 . The first line contains an integer t ( 1 <= t <= 10^4 ) -- the number of test cases. The first line of each test case contains two integers n and k ( 1 <= k <= n <= 2 cdot 10^5 ) -- the number of vertices in the tree and the number of marked vertices, respectively. The second line of each test case contains k integers a_i ( 1 <= a_i <= n, a_{i-1} < a_i ) -- the indices of the marked vertices. The next n - 1 lines contain two integers u_i and v_i -- the indices of vertices connected by the i -th edge. It is guaranteed that the sum of n over all test cases does not exceed 2 cdot 10^5 . For each test case, output a single integer -- the minimum value of f_i among all vertices. '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
227928116 |
LostTemple |
F |
Oct. 12, 2023, 5:04 p.m. |
OK |
C# 10 |
TESTS |
42 |
764 |
58982400 |
|
|
227961695 |
lhy123 |
F |
Oct. 13, 2023, 12:32 a.m. |
OK |
GNU C++14 |
TESTS |
42 |
109 |
18841600 |
|
|
227931465 |
Li_yi_hang |
F |
Oct. 12, 2023, 5:22 p.m. |
OK |
GNU C++14 |
TESTS |
42 |
140 |
7372800 |
|
|
227968923 |
yzj123 |
F |
Oct. 13, 2023, 2:54 a.m. |
OK |
GNU C++14 |
TESTS |
42 |
155 |
13926400 |
|
|
227934765 |
leidianfei |
F |
Oct. 12, 2023, 5:45 p.m. |
OK |
GNU C++14 |
TESTS |
42 |
171 |
7987200 |
|
|
227953364 |
Rafael_Y |
F |
Oct. 12, 2023, 9:07 p.m. |
OK |
GNU C++14 |
TESTS |
42 |
186 |
14028800 |
|
|
227958015 |
omeganot |
F |
Oct. 12, 2023, 10:49 p.m. |
OK |
GNU C++14 |
TESTS |
42 |
187 |
18022400 |
|
|
227958444 |
sievra |
F |
Oct. 12, 2023, 11:01 p.m. |
OK |
GNU C++14 |
TESTS |
42 |
187 |
21299200 |
|
|
227929774 |
Linver |
F |
Oct. 12, 2023, 5:12 p.m. |
OK |
GNU C++14 |
TESTS |
42 |
202 |
8192000 |
|
|
227969171 |
kuguadawang |
F |
Oct. 13, 2023, 2:59 a.m. |
OK |
GNU C++14 |
TESTS |
42 |
202 |
9011200 |
|
|
227982250 |
marcus06 |
F |
Oct. 13, 2023, 5:57 a.m. |
OK |
GNU C++14 |
TESTS |
42 |
202 |
9830400 |
|
|
227965880 |
liuyz11 |
F |
Oct. 13, 2023, 2:02 a.m. |
OK |
GNU C++17 |
TESTS |
42 |
155 |
16691200 |
|
|
227925010 |
cloud_Ann |
F |
Oct. 12, 2023, 4:52 p.m. |
OK |
GNU C++17 |
TESTS |
42 |
171 |
15462400 |
|
|
227962782 |
Charming |
F |
Oct. 13, 2023, 12:59 a.m. |
OK |
GNU C++17 |
TESTS |
42 |
171 |
21094400 |
|
|
227946799 |
gabriel88766 |
F |
Oct. 12, 2023, 7:37 p.m. |
OK |
GNU C++17 |
TESTS |
42 |
186 |
8396800 |
|
|
227981630 |
Tri17 |
F |
Oct. 13, 2023, 5:50 a.m. |
OK |
GNU C++17 |
TESTS |
42 |
186 |
16588800 |
|
|
227960188 |
pavlukivan |
F |
Oct. 12, 2023, 11:51 p.m. |
OK |
GNU C++17 |
TESTS |
42 |
187 |
11366400 |
|
|
227928800 |
Palbudir |
F |
Oct. 12, 2023, 5:07 p.m. |
OK |
GNU C++17 |
TESTS |
42 |
187 |
12492800 |
|
|
227926820 |
mbulge |
F |
Oct. 12, 2023, 4:58 p.m. |
OK |
GNU C++17 |
TESTS |
42 |
187 |
14131200 |
|
|
227965373 |
Harshit_Singh |
F |
Oct. 13, 2023, 1:52 a.m. |
OK |
GNU C++17 |
TESTS |
42 |
187 |
16179200 |
|
|
227945006 |
what-a-drag |
F |
Oct. 12, 2023, 7:18 p.m. |
OK |
GNU C++17 |
TESTS |
42 |
187 |
18124800 |
|
|
227977553 |
XH_v |
F |
Oct. 13, 2023, 5:03 a.m. |
OK |
GNU C++17 (64) |
TESTS |
42 |
124 |
22425600 |
|
|
227968349 |
csustyyt |
F |
Oct. 13, 2023, 2:45 a.m. |
OK |
GNU C++17 (64) |
TESTS |
42 |
140 |
99123200 |
|
|
227926120 |
lxllxs |
F |
Oct. 12, 2023, 4:56 p.m. |
OK |
GNU C++17 (64) |
TESTS |
42 |
156 |
34201600 |
|
|
227979299 |
Rogi52 |
F |
Oct. 13, 2023, 5:25 a.m. |
OK |
GNU C++17 (64) |
TESTS |
42 |
171 |
12492800 |
|
|
227982491 |
4Ace |
F |
Oct. 13, 2023, 6 a.m. |
OK |
GNU C++17 (64) |
TESTS |
42 |
171 |
15564800 |
|
|
227933316 |
pipipipipi43 |
F |
Oct. 12, 2023, 5:34 p.m. |
OK |
GNU C++17 (64) |
TESTS |
42 |
171 |
26726400 |
|
|
227955849 |
efishel |
F |
Oct. 12, 2023, 9:57 p.m. |
OK |
GNU C++17 (64) |
TESTS |
42 |
186 |
14028800 |
|
|
227940480 |
illyakr |
F |
Oct. 12, 2023, 6:33 p.m. |
OK |
GNU C++17 (64) |
TESTS |
42 |
186 |
27852800 |
|
|
227977938 |
lakshmankattunga |
F |
Oct. 13, 2023, 5:07 a.m. |
OK |
GNU C++17 (64) |
TESTS |
42 |
186 |
28467200 |
|
|
227933894 |
Teranj |
F |
Oct. 12, 2023, 5:38 p.m. |
OK |
GNU C++17 (64) |
TESTS |
42 |
187 |
30310400 |
|
|
227976185 |
_Golem_ |
F |
Oct. 13, 2023, 4:44 a.m. |
OK |
GNU C++20 (64) |
TESTS |
42 |
78 |
56422400 |
|
|
227933303 |
hbkxyz |
F |
Oct. 12, 2023, 5:34 p.m. |
OK |
GNU C++20 (64) |
TESTS |
42 |
108 |
20787200 |
|
|
227929867 |
_andyli |
F |
Oct. 12, 2023, 5:12 p.m. |
OK |
GNU C++20 (64) |
TESTS |
42 |
109 |
18329600 |
|
|
227977156 |
Aitejiu |
F |
Oct. 13, 2023, 4:57 a.m. |
OK |
GNU C++20 (64) |
TESTS |
42 |
109 |
23961600 |
|
|
227929131 |
zeemanz |
F |
Oct. 12, 2023, 5:09 p.m. |
OK |
GNU C++20 (64) |
TESTS |
42 |
109 |
27750400 |
|
|
227966865 |
xiojoy |
F |
Oct. 13, 2023, 2:21 a.m. |
OK |
GNU C++20 (64) |
TESTS |
42 |
124 |
10137600 |
|
|
227962601 |
Susie.Rain |
F |
Oct. 13, 2023, 12:55 a.m. |
OK |
GNU C++20 (64) |
TESTS |
42 |
124 |
26316800 |
|
|
227929724 |
_andyli |
F |
Oct. 12, 2023, 5:12 p.m. |
OK |
GNU C++20 (64) |
TESTS |
42 |
124 |
28774400 |
|
|
227924859 |
jiujiumaomaoniang |
F |
Oct. 12, 2023, 4:52 p.m. |
OK |
GNU C++20 (64) |
TESTS |
42 |
124 |
73318400 |
|
|
227974692 |
rxhxn_30 |
F |
Oct. 13, 2023, 4:22 a.m. |
OK |
GNU C++20 (64) |
TESTS |
42 |
140 |
10137600 |
|
|
227952426 |
Kempachi |
F |
Oct. 12, 2023, 8:51 p.m. |
OK |
Java 11 |
TESTS |
42 |
748 |
35225600 |
|
|
227979244 |
wdjuruo |
F |
Oct. 13, 2023, 5:24 a.m. |
OK |
Java 11 |
TESTS |
42 |
1076 |
195379200 |
|
|
227961273 |
themadknight45 |
F |
Oct. 13, 2023, 12:22 a.m. |
OK |
Java 11 |
TESTS |
42 |
1606 |
98713600 |
|
|
227979153 |
wdjuruo |
F |
Oct. 13, 2023, 5:23 a.m. |
OK |
Java 11 |
TESTS |
42 |
1668 |
201830400 |
|
|
227981139 |
TopCloser |
F |
Oct. 13, 2023, 5:45 a.m. |
OK |
Java 17 |
TESTS |
42 |
936 |
83353600 |
|
|
227933765 |
vaibhav_1710 |
F |
Oct. 12, 2023, 5:37 p.m. |
OK |
Java 17 |
TESTS |
42 |
982 |
106905600 |
|
|
227956567 |
NerfThis |
F |
Oct. 12, 2023, 10:11 p.m. |
OK |
Java 8 |
TESTS |
42 |
748 |
41369600 |
|
|
227924012 |
nicnic4102 |
F |
Oct. 12, 2023, 4:49 p.m. |
OK |
Kotlin 1.7 |
TESTS |
42 |
1653 |
187699200 |
|
|
227925828 |
Golovanov399 |
F |
Oct. 12, 2023, 4:55 p.m. |
OK |
Kotlin 1.7 |
TESTS |
42 |
1809 |
185651200 |
|
|
227974323 |
AllDirections |
F |
Oct. 13, 2023, 4:17 a.m. |
OK |
MS C++ 2017 |
TESTS |
42 |
764 |
65945600 |
|
|
227927645 |
chinesedfan |
F |
Oct. 12, 2023, 5:02 p.m. |
OK |
Node.js |
TESTS |
42 |
1044 |
73625600 |
|
|
227972206 |
YMSeah |
F |
Oct. 13, 2023, 3:46 a.m. |
OK |
PyPy 3 |
TESTS |
42 |
1091 |
80179200 |
|
|
227948679 |
gardengnome |
F |
Oct. 12, 2023, 8 p.m. |
OK |
PyPy 3-64 |
TESTS |
42 |
421 |
34099200 |
|
|
227975348 |
cy171 |
F |
Oct. 13, 2023, 4:32 a.m. |
OK |
PyPy 3-64 |
TESTS |
42 |
467 |
32972800 |
|
|
227967213 |
liuaaa |
F |
Oct. 13, 2023, 2:27 a.m. |
OK |
PyPy 3-64 |
TESTS |
42 |
467 |
45056000 |
|
|
227963089 |
cybsbbb |
F |
Oct. 13, 2023, 1:06 a.m. |
OK |
PyPy 3-64 |
TESTS |
42 |
482 |
44236800 |
|
|
227948819 |
gardengnome |
F |
Oct. 12, 2023, 8:02 p.m. |
OK |
PyPy 3-64 |
TESTS |
42 |
483 |
32972800 |
|
|
227930650 |
yuki_keshiki |
F |
Oct. 12, 2023, 5:17 p.m. |
OK |
PyPy 3-64 |
TESTS |
42 |
483 |
45056000 |
|
|
227931254 |
DottedCalculator |
F |
Oct. 12, 2023, 5:20 p.m. |
OK |
PyPy 3-64 |
TESTS |
42 |
592 |
41369600 |
|
|
227963460 |
pyrogyx |
F |
Oct. 13, 2023, 1:14 a.m. |
OK |
PyPy 3-64 |
TESTS |
42 |
592 |
61235200 |
|
|
227976156 |
harshk_52 |
F |
Oct. 13, 2023, 4:44 a.m. |
OK |
PyPy 3-64 |
TESTS |
42 |
623 |
81510400 |
|
|
227968193 |
liuaaa |
F |
Oct. 13, 2023, 2:42 a.m. |
OK |
PyPy 3-64 |
TESTS |
42 |
670 |
62873600 |
|
|
227979550 |
bqn |
F |
Oct. 13, 2023, 5:28 a.m. |
OK |
Rust 2021 |
TESTS |
42 |
436 |
133017600 |
|
|
remove filters
Back to search problems