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 an undirected unweighted tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges. Your task is to choose two pairs of vertices of this tree (all the chosen vertices should be distinct) (x_1, y_1) and (x_2, y_2) in such a way that neither x_1 nor y_1 belong to the simple path from x_2 to y_2 and vice versa (neither x_2 nor y_2 should not belong to the simple path from x_1 to y_1 ). It is guaranteed that it is possible to choose such pairs for the given tree. Among all possible ways to choose such pairs you have to choose one with the maximum number of common vertices between paths from x_1 to y_1 and from x_2 to y_2 . And among all such pairs you have to choose one with the maximum total length of these two paths. It is guaranteed that the answer with at least two common vertices exists for the given tree. The length of the path is the number of edges in it. The simple path is the path that visits each vertex at most once. The first line contains an integer n -- the number of vertices in the tree ( 6 <= n <= 2 cdot 10^5 ). Each of the next n - 1 lines describes the edges of the tree. Edge i is denoted by two integers u_i and v_i , the labels of vertices it connects ( 1 <= u_i, v_i <= n , u_i ne v_i ). It is guaranteed that the given edges form a tree. It is guaranteed that the answer with at least two common vertices exists for the given tree. Print any two pairs of vertices satisfying the conditions described in the problem statement. It is guaranteed that it is possible to choose such pairs for the given tree. The picture corresponding to the first example: The intersection of two paths is 2 (vertices 1 and 4 ) and the total length is 4 + 3 = 7 . The picture corresponding to the second example: The intersection of two paths is 2 '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
50285122 |
xielinhan |
F |
Feb. 21, 2019, 2:29 p.m. |
OK |
GNU C++11 |
TESTS |
83 |
62 |
19251200 |
|
2800 |
44972332 |
_CZH |
F |
Oct. 28, 2018, 1:47 a.m. |
OK |
GNU C++11 |
TESTS |
83 |
62 |
19251200 |
|
2800 |
45076178 |
oiervictor |
F |
Oct. 30, 2018, 12:44 a.m. |
OK |
GNU C++11 |
TESTS |
83 |
77 |
9625600 |
|
2800 |
48657232 |
ReaLNero1 |
F |
Jan. 21, 2019, 3:36 a.m. |
OK |
GNU C++11 |
TESTS |
83 |
77 |
19251200 |
|
2800 |
45075852 |
zhou2003 |
F |
Oct. 30, 2018, 12:15 a.m. |
OK |
GNU C++11 |
TESTS |
83 |
77 |
19251200 |
|
2800 |
48026473 |
SylvanasS |
F |
Jan. 6, 2019, 9:25 a.m. |
OK |
GNU C++11 |
TESTS |
83 |
77 |
29798400 |
|
2800 |
44890730 |
qkoqhh |
F |
Oct. 26, 2018, 3:06 a.m. |
OK |
GNU C++11 |
TESTS |
83 |
78 |
13004800 |
|
2800 |
64153012 |
luogu_bot5 |
F |
Nov. 3, 2019, 11:58 a.m. |
OK |
GNU C++11 |
TESTS |
83 |
78 |
15974400 |
|
2800 |
64152563 |
Rachel_in |
F |
Nov. 3, 2019, 11:52 a.m. |
OK |
GNU C++11 |
TESTS |
83 |
78 |
15974400 |
|
2800 |
60149743 |
orzorz_moeDzW |
F |
Sept. 6, 2019, 3:07 a.m. |
OK |
GNU C++11 |
TESTS |
83 |
78 |
15974400 |
|
2800 |
45537056 |
xiaolongbao |
F |
Nov. 10, 2018, 5:01 p.m. |
OK |
GNU C++14 |
TESTS |
83 |
124 |
10035200 |
|
2800 |
45145729 |
Vinhspm |
F |
Oct. 31, 2018, 4:46 p.m. |
OK |
GNU C++14 |
TESTS |
83 |
124 |
15974400 |
|
2800 |
45053074 |
dujvet |
F |
Oct. 29, 2018, 11:35 a.m. |
OK |
GNU C++14 |
TESTS |
83 |
139 |
16588800 |
|
2800 |
45037986 |
shaochengxi |
F |
Oct. 29, 2018, 8:47 a.m. |
OK |
GNU C++14 |
TESTS |
83 |
139 |
17612800 |
|
2800 |
45963672 |
LittleFairyMY |
F |
Nov. 19, 2018, 12:52 p.m. |
OK |
GNU C++14 |
TESTS |
83 |
139 |
19251200 |
|
2800 |
45479897 |
xiaolongbao |
F |
Nov. 9, 2018, 2:16 p.m. |
OK |
GNU C++14 |
TESTS |
83 |
140 |
17612800 |
|
2800 |
50319873 |
transs |
F |
Feb. 22, 2019, 1:59 p.m. |
OK |
GNU C++14 |
TESTS |
83 |
156 |
15974400 |
|
2800 |
44893170 |
Marckess |
F |
Oct. 26, 2018, 4:49 a.m. |
OK |
GNU C++14 |
TESTS |
83 |
171 |
14643200 |
|
2800 |
45037901 |
dwt |
F |
Oct. 29, 2018, 8:45 a.m. |
OK |
GNU C++14 |
TESTS |
83 |
171 |
15769600 |
|
2800 |
50319971 |
transs |
F |
Feb. 22, 2019, 2:03 p.m. |
OK |
GNU C++14 |
TESTS |
83 |
171 |
15974400 |
|
2800 |
52664709 |
gerard.lin |
F |
April 13, 2019, 3:46 a.m. |
OK |
GNU C++17 |
TESTS |
83 |
140 |
17612800 |
|
2800 |
50315101 |
happy_ |
F |
Feb. 22, 2019, 11:52 a.m. |
OK |
GNU C++17 |
TESTS |
83 |
140 |
19251200 |
|
2800 |
44898762 |
des3ns1tized_ |
F |
Oct. 26, 2018, 7:59 a.m. |
OK |
GNU C++17 |
TESTS |
83 |
171 |
9830400 |
|
2800 |
45874078 |
Dream_d |
F |
Nov. 17, 2018, 11:12 a.m. |
OK |
GNU C++17 |
TESTS |
83 |
171 |
19456000 |
|
2800 |
48670102 |
zhangqingqi |
F |
Jan. 21, 2019, 10:22 a.m. |
OK |
GNU C++17 |
TESTS |
83 |
171 |
20787200 |
|
2800 |
63772888 |
pootis |
F |
Oct. 30, 2019, 8:36 a.m. |
OK |
GNU C++17 |
TESTS |
83 |
187 |
12288000 |
|
2800 |
45467080 |
endereye |
F |
Nov. 9, 2018, 6:45 a.m. |
OK |
GNU C++17 |
TESTS |
83 |
187 |
20992000 |
|
2800 |
45133503 |
dx007 |
F |
Oct. 31, 2018, 11:23 a.m. |
OK |
GNU C++17 |
TESTS |
83 |
187 |
20992000 |
|
2800 |
68072178 |
kostia244 |
F |
Jan. 2, 2020, 10:50 a.m. |
OK |
GNU C++17 |
TESTS |
83 |
187 |
23347200 |
|
2800 |
44898329 |
HDMMBLZ |
F |
Oct. 26, 2018, 7:45 a.m. |
OK |
GNU C++17 |
TESTS |
83 |
187 |
38604800 |
|
2800 |
67967326 |
dalt |
F |
Dec. 30, 2019, 1:47 p.m. |
OK |
Java 8 |
TESTS |
83 |
701 |
129740800 |
|
2800 |
62677045 |
vjudge1 |
F |
Oct. 16, 2019, 11:44 a.m. |
OK |
MS C++ |
TESTS |
83 |
202 |
16793600 |
|
2800 |
45076319 |
marcv81 |
F |
Oct. 30, 2018, 12:58 a.m. |
OK |
Python 3 |
TESTS |
83 |
1309 |
43110400 |
|
2800 |
45076211 |
marcv81 |
F |
Oct. 30, 2018, 12:48 a.m. |
OK |
Python 3 |
TESTS |
83 |
1419 |
43110400 |
|
2800 |
47019560 |
whatshisbucket |
F |
Dec. 14, 2018, 10:39 p.m. |
OK |
Python 3 |
TESTS |
83 |
1996 |
73420800 |
|
2800 |
remove filters
Back to search problems