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 are given a tree consisting of n vertices. Initially, each vertex has a value 0 . You need to perform m queries of two types: The distance between two vertices x and y is equal to the number of edges on the path from x to y . For example, the distance from x to x itself is equal to 0 . The distance from the vertex v to some path from x to y is equal to the minimum among distances from v to any vertex on the path from x to y . The first line contains a single integer n ( 2 <= n <= 2 cdot 10^5 ) -- the number of vertices in the tree. Next n - 1 lines contain the edges of the tree -- one per line. Each line contains two integers u and v ( 1 <= u, v <= n ; u neq v ) representing one edge of the tree. It's guaranteed that the given edges form a tree. The next line contains a single integer m ( 1 <= m <= 2 cdot 10^5 ) -- the number of queries. Next m lines contain the queries -- one per line. Each query has one of the following two types: Additional constraint on the input: there is at least one query of the first type. For each query of the first type, print the value of the corresponding vertex. The tree from the first example: "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
177215236 |
M0stapha_Taha |
F |
Oct. 20, 2022, 4:56 p.m. |
OK |
GNU C++14 |
TESTS |
95 |
780 |
54272000 |
|
|
177251981 |
xianggl |
F |
Oct. 21, 2022, 2:49 a.m. |
OK |
GNU C++14 |
TESTS |
95 |
795 |
57344000 |
|
|
177211636 |
wiIIiam555 |
F |
Oct. 20, 2022, 4:37 p.m. |
OK |
GNU C++14 |
TESTS |
95 |
857 |
54272000 |
|
|
177250731 |
Krystallos |
F |
Oct. 21, 2022, 2:26 a.m. |
OK |
GNU C++14 |
TESTS |
95 |
857 |
57344000 |
|
|
177257046 |
vjudge1 |
F |
Oct. 21, 2022, 4:18 a.m. |
OK |
GNU C++14 |
TESTS |
95 |
951 |
70246400 |
|
|
177256958 |
L7-56 |
F |
Oct. 21, 2022, 4:16 a.m. |
OK |
GNU C++14 |
TESTS |
95 |
966 |
70246400 |
|
|
177212223 |
xtzic |
F |
Oct. 20, 2022, 4:40 p.m. |
OK |
GNU C++14 |
TESTS |
95 |
1060 |
39936000 |
|
|
177253285 |
Leasier |
F |
Oct. 21, 2022, 3:13 a.m. |
OK |
GNU C++14 |
TESTS |
95 |
1653 |
81203200 |
|
|
177245469 |
JoesSR |
F |
Oct. 21, 2022, 12:23 a.m. |
OK |
GNU C++14 |
TESTS |
95 |
2449 |
58060800 |
|
|
177263834 |
Liu_Kevin |
F |
Oct. 21, 2022, 5:55 a.m. |
OK |
GNU C++14 |
TESTS |
95 |
3104 |
39424000 |
|
|
177249435 |
_Sunrise_ |
F |
Oct. 21, 2022, 1:59 a.m. |
OK |
GNU C++17 |
TESTS |
95 |
748 |
83763200 |
|
|
177259492 |
mirzoevbezhan.01 |
F |
Oct. 21, 2022, 4:58 a.m. |
OK |
GNU C++17 |
TESTS |
95 |
811 |
54272000 |
|
|
177253768 |
zja601 |
F |
Oct. 21, 2022, 3:22 a.m. |
OK |
GNU C++17 |
TESTS |
95 |
826 |
62156800 |
|
|
177215335 |
dmenezes |
F |
Oct. 20, 2022, 4:56 p.m. |
OK |
GNU C++17 |
TESTS |
95 |
841 |
54272000 |
|
|
177219981 |
farhanLabib2537 |
F |
Oct. 20, 2022, 5:31 p.m. |
OK |
GNU C++17 |
TESTS |
95 |
888 |
102297600 |
|
|
177215270 |
leilaqwq |
F |
Oct. 20, 2022, 4:56 p.m. |
OK |
GNU C++17 |
TESTS |
95 |
888 |
102297600 |
|
|
177251928 |
huyaowen |
F |
Oct. 21, 2022, 2:48 a.m. |
OK |
GNU C++17 |
TESTS |
95 |
951 |
52428800 |
|
|
177263453 |
HaiYen |
F |
Oct. 21, 2022, 5:50 a.m. |
OK |
GNU C++17 |
TESTS |
95 |
982 |
112742400 |
|
|
177251949 |
huyaowen |
F |
Oct. 21, 2022, 2:48 a.m. |
OK |
GNU C++17 |
TESTS |
95 |
997 |
52428800 |
|
|
177250007 |
Lomk |
F |
Oct. 21, 2022, 2:11 a.m. |
OK |
GNU C++17 |
TESTS |
95 |
2807 |
170803200 |
|
|
177215844 |
hitonanode |
F |
Oct. 20, 2022, 4:59 p.m. |
OK |
GNU C++17 (64) |
TESTS |
95 |
654 |
53043200 |
|
|
177215523 |
hitonanode |
F |
Oct. 20, 2022, 4:57 p.m. |
OK |
GNU C++17 (64) |
TESTS |
95 |
701 |
53043200 |
|
|
177215051 |
hitonanode |
F |
Oct. 20, 2022, 4:55 p.m. |
OK |
GNU C++17 (64) |
TESTS |
95 |
763 |
36147200 |
|
|
177209131 |
akifpatel |
F |
Oct. 20, 2022, 4:31 p.m. |
OK |
GNU C++17 (64) |
TESTS |
95 |
1777 |
271872000 |
|
|
177206430 |
noimi |
F |
Oct. 20, 2022, 4:24 p.m. |
OK |
GNU C++17 (64) |
TESTS |
95 |
1871 |
108544000 |
|
|
177218174 |
kdh9949 |
F |
Oct. 20, 2022, 5:16 p.m. |
OK |
GNU C++17 (64) |
TESTS |
95 |
1871 |
132198400 |
|
|
177210951 |
Hyperbolic |
F |
Oct. 20, 2022, 4:34 p.m. |
OK |
GNU C++17 (64) |
TESTS |
95 |
3962 |
188006400 |
|
|
177215347 |
CuKing |
F |
Oct. 20, 2022, 4:56 p.m. |
OK |
GNU C++17 (64) |
TESTS |
95 |
3993 |
291840000 |
|
|
177202230 |
gyh20 |
F |
Oct. 20, 2022, 4:13 p.m. |
OK |
GNU C++20 (64) |
TESTS |
95 |
780 |
47820800 |
|
|
177230500 |
BlueDiamond |
F |
Oct. 20, 2022, 7:21 p.m. |
OK |
GNU C++20 (64) |
TESTS |
95 |
966 |
186982400 |
|
|
177207398 |
yyyz04 |
F |
Oct. 20, 2022, 4:27 p.m. |
OK |
GNU C++20 (64) |
TESTS |
95 |
1029 |
69017600 |
|
|
177248334 |
victor.gao |
F |
Oct. 21, 2022, 1:34 a.m. |
OK |
GNU C++20 (64) |
TESTS |
95 |
1045 |
247808000 |
|
|
177251434 |
BaoJiaoPisu |
F |
Oct. 21, 2022, 2:39 a.m. |
OK |
GNU C++20 (64) |
TESTS |
95 |
1060 |
119500800 |
|
|
177205944 |
brunovsky |
F |
Oct. 20, 2022, 4:23 p.m. |
OK |
GNU C++20 (64) |
TESTS |
95 |
1123 |
133017600 |
|
|
177204743 |
oleh1421 |
F |
Oct. 20, 2022, 4:20 p.m. |
OK |
GNU C++20 (64) |
TESTS |
95 |
1294 |
67174400 |
|
|
177251299 |
Macesuted-Moe |
F |
Oct. 21, 2022, 2:37 a.m. |
OK |
GNU C++20 (64) |
TESTS |
95 |
1419 |
104857600 |
|
|
177218922 |
Nero |
F |
Oct. 20, 2022, 5:22 p.m. |
OK |
GNU C++20 (64) |
TESTS |
95 |
1481 |
139980800 |
|
|
177224979 |
Windy233 |
F |
Oct. 20, 2022, 6:18 p.m. |
OK |
GNU C++20 (64) |
TESTS |
95 |
1496 |
78540800 |
|
|
remove filters
Back to search problems