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'There is a tree of N vertices and N-1 edges. The i -th edge connects vertices U_i and V_i and has a length of W_i . Chaneka, the owner of the tree, asks you Q times. For the j -th question, the following is the question format: Notes: The first line contains a single integer N ( 2 <= q N <= q10^5 ) -- the number of vertices in the tree. The i -th of the next N-1 lines contains three integers U_i , V_i , and W_i ( 1 <= q U_i,V_i <= q N ; 1 <= q W_i <= q10^9 ) -- an edge that connects vertices U_i and V_i with a length of W_i . The edges form a tree. The (N+1) -th line contains a single integer Q ( 1 <= q Q <= q10^5 ) -- the number of questions. The j -th of the next Q lines contains two integers X_j and K_j as described ( 1 <= q X_j <= q N ; 1 <= q K_j <= q 10^9 ). Output Q lines with an integer in each line. The integer in the j -th line represents the diameter of the tree on the j -th question. In the first example, the following is the tree without any changes. The following is the tree on the 1 -st question. The maximum distance is between vertices 6 and 7 , which is 6+6+6=18 , so the diameter is 18 . The following is the tree on the 2 -nd question. The maximum distance is between vertices 2 and 6 , which is 3+2+6=11 , so the diameter is 11 . '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
221708220 |
IceYukino pp_orange cxm1024 |
K |
Sept. 3, 2023, 2:56 p.m. |
OK |
GNU C++14 |
TESTS |
41 |
358 |
84070400 |
|
|
221775193 |
Pyqe |
K |
Sept. 4, 2023, 5:48 a.m. |
OK |
GNU C++17 |
TESTS |
41 |
295 |
26828800 |
|
|
221704088 |
potato167 |
K |
Sept. 3, 2023, 2:31 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
326 |
22016000 |
|
|
221701139 |
riconduongcung |
K |
Sept. 3, 2023, 2:15 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
326 |
29900800 |
|
|
221707553 |
TeasingMaster WHC-MIK-7521X |
K |
Sept. 3, 2023, 2:51 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
374 |
50483200 |
|
|
221711812 |
Kuroni |
K |
Sept. 3, 2023, 3:19 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
405 |
26214400 |
|
|
221709860 |
hank55663 |
K |
Sept. 3, 2023, 3:06 p.m. |
OK |
GNU C++17 |
TESTS |
41 |
483 |
47616000 |
|
|
221773215 |
Sai_Rohit-30021 |
K |
Sept. 4, 2023, 5:20 a.m. |
OK |
GNU C++17 |
TESTS |
41 |
1949 |
389017600 |
|
|
221766828 |
srivathsava_337 |
K |
Sept. 4, 2023, 3:33 a.m. |
OK |
GNU C++17 |
TESTS |
41 |
1949 |
389017600 |
|
|
221762239 |
hellojim |
K |
Sept. 4, 2023, 2:01 a.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
280 |
40960000 |
|
|
221712781 |
K-H ttcwws CodingJellyfish |
K |
Sept. 3, 2023, 3:25 p.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
295 |
52224000 |
|
|
221774176 |
alif_cse_ju |
K |
Sept. 4, 2023, 5:33 a.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
326 |
39014400 |
|
|
221713806 |
kotatsugame |
K |
Sept. 3, 2023, 3:32 p.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
326 |
55500800 |
|
|
221716368 |
eggag32 shcal devinqu |
K |
Sept. 3, 2023, 3:50 p.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
358 |
66457600 |
|
|
221722731 |
crescent_yhw TheAshenWitch yuanhaowei |
K |
Sept. 3, 2023, 4:36 p.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
374 |
68608000 |
|
|
221707573 |
noimi SSRS_ |
K |
Sept. 3, 2023, 2:52 p.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
405 |
70963200 |
|
|
221712136 |
Morphymorphymorphy |
K |
Sept. 3, 2023, 3:21 p.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
468 |
28672000 |
|
|
221774230 |
alif_cse_ju |
K |
Sept. 4, 2023, 5:34 a.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
483 |
28672000 |
|
|
221724768 |
sapphire15 tokusakurai torisasami |
K |
Sept. 3, 2023, 4:51 p.m. |
OK |
GNU C++17 (64) |
TESTS |
41 |
483 |
49664000 |
|
|
221730989 |
SSerxhs |
K |
Sept. 3, 2023, 5:44 p.m. |
OK |
GNU C++20 (64) |
TESTS |
41 |
202 |
28876800 |
|
|
221719755 |
maximumSHOT |
K |
Sept. 3, 2023, 4:14 p.m. |
OK |
GNU C++20 (64) |
TESTS |
41 |
234 |
44134400 |
|
|
221727214 |
ItsJerr |
K |
Sept. 3, 2023, 5:09 p.m. |
OK |
GNU C++20 (64) |
TESTS |
41 |
249 |
23961600 |
|
|
221708347 |
THA karrigan0108 lmqzzz |
K |
Sept. 3, 2023, 2:57 p.m. |
OK |
GNU C++20 (64) |
TESTS |
41 |
249 |
29491200 |
|
|
221721671 |
bachbeo2007 |
K |
Sept. 3, 2023, 4:29 p.m. |
OK |
GNU C++20 (64) |
TESTS |
41 |
249 |
35123200 |
|
|
221715072 |
red-stone LXH-cat wsyear |
K |
Sept. 3, 2023, 3:41 p.m. |
OK |
GNU C++20 (64) |
TESTS |
41 |
249 |
73830400 |
|
|
221770817 |
karrigan0108 |
K |
Sept. 4, 2023, 4:42 a.m. |
OK |
GNU C++20 (64) |
TESTS |
41 |
264 |
29491200 |
|
|
221701111 |
353cerega 244mhq |
K |
Sept. 3, 2023, 2:15 p.m. |
OK |
GNU C++20 (64) |
TESTS |
41 |
265 |
27648000 |
|
|
221774788 |
BuddhaBarFans |
K |
Sept. 4, 2023, 5:42 a.m. |
OK |
GNU C++20 (64) |
TESTS |
41 |
265 |
35840000 |
|
|
221695637 |
jiangly |
K |
Sept. 3, 2023, 1:46 p.m. |
OK |
GNU C++20 (64) |
TESTS |
41 |
265 |
35840000 |
|
|
remove filters
Back to search problems