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'Sasha was given a tree ^{ dagger} with n vertices as a prize for winning yet another competition. However, upon returning home after celebrating his victory, he noticed that some parts of the tree were missing. Sasha remembers that he colored some of the edges of this tree. He is certain that for any of the k pairs of vertices (a_1, b_1), ldots, (a_k, b_k) , he colored at least one edge on the simple path ^{ ddagger} between vertices a_i and b_i . Sasha does not remember how many edges he exactly colored, so he asks you to tell him the minimum number of edges he could have colored to satisfy the above condition. ^{ dagger} A tree is an undirected connected graph without cycles. ^{ ddagger} A simple path is a path that passes through each vertex at most once. Each test consists of multiple test cases. The first line contains a single integer t ( 1 <= t <= 10^4 ) -- the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n ( 2 <= q n <= q 10^5 ) -- the number of vertices in the tree. The next (n - 1) lines describe the edges of the tree. The i -th line contains two integers u_i and v_i ( 1 <= q u_i, v_i <= q n , u_i ne v_i ) -- the numbers of the vertices connected by the i -th edge. The next line contains a single integer k ( 1 <= q k <= q 20 ) -- the number of pairs of vertices between which Sasha colored at least one edge on a simple path. The next k lines describe pairs. The j -th line contains two integers a_j and b_j ( 1 <= q a_j, b_j <= q n, a_j neq b_j ) -- the vertices in the j -th pair. It is guaranteed that the sum of n over all test cases does not exceed 10^5 . It is guaranteed that the sum of 2^k over all test cases does not exceed 2^{20} . For each test case, output a single integer -- the mini'... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
246559204 |
Gassa |
E |
Feb. 15, 2024, 4:23 p.m. |
OK |
D |
TESTS |
54 |
1154 |
18534400 |
|
|
246590031 |
rainboy |
E |
Feb. 15, 2024, 8:17 p.m. |
OK |
GNU C11 |
TESTS |
54 |
93 |
9932800 |
|
|
246604778 |
daniel604 |
E |
Feb. 16, 2024, 1:07 a.m. |
OK |
GNU C++17 |
TESTS |
54 |
108 |
24678400 |
|
|
246578993 |
Jarif_Rahman |
E |
Feb. 15, 2024, 6:25 p.m. |
OK |
GNU C++17 |
TESTS |
54 |
124 |
13414400 |
|
|
246609841 |
Teemka |
E |
Feb. 16, 2024, 2:54 a.m. |
OK |
GNU C++17 |
TESTS |
54 |
124 |
17920000 |
|
|
246581651 |
llzer |
E |
Feb. 15, 2024, 6:49 p.m. |
OK |
GNU C++17 |
TESTS |
54 |
139 |
17100800 |
|
|
246562458 |
IBory |
E |
Feb. 15, 2024, 4:31 p.m. |
OK |
GNU C++17 |
TESTS |
54 |
140 |
15564800 |
|
|
246581365 |
llzer |
E |
Feb. 15, 2024, 6:46 p.m. |
OK |
GNU C++17 |
TESTS |
54 |
140 |
17100800 |
|
|
246556543 |
llzer |
E |
Feb. 15, 2024, 4:16 p.m. |
OK |
GNU C++17 |
TESTS |
54 |
155 |
17100800 |
|
|
246581202 |
llzer |
E |
Feb. 15, 2024, 6:45 p.m. |
OK |
GNU C++17 |
TESTS |
54 |
155 |
17100800 |
|
|
246601517 |
int65536 |
E |
Feb. 15, 2024, 11:33 p.m. |
OK |
GNU C++17 |
TESTS |
54 |
155 |
18944000 |
|
|
246566224 |
qwerty190 |
E |
Feb. 15, 2024, 4:58 p.m. |
OK |
GNU C++17 |
TESTS |
54 |
155 |
22016000 |
|
|
246619903 |
pengpeng_fudan |
E |
Feb. 16, 2024, 5:26 a.m. |
OK |
GNU C++17 (64) |
TESTS |
54 |
108 |
20787200 |
|
|
246607658 |
enslaved |
E |
Feb. 16, 2024, 2:09 a.m. |
OK |
GNU C++17 (64) |
TESTS |
54 |
139 |
36454400 |
|
|
246612410 |
yangchang |
E |
Feb. 16, 2024, 3:38 a.m. |
OK |
GNU C++17 (64) |
TESTS |
54 |
140 |
21401600 |
|
|
246614185 |
Misty7 |
E |
Feb. 16, 2024, 4:04 a.m. |
OK |
GNU C++17 (64) |
TESTS |
54 |
155 |
21811200 |
|
|
246614502 |
naroanah |
E |
Feb. 16, 2024, 4:09 a.m. |
OK |
GNU C++17 (64) |
TESTS |
54 |
170 |
24576000 |
|
|
246620151 |
ChinoKafuu |
E |
Feb. 16, 2024, 5:29 a.m. |
OK |
GNU C++17 (64) |
TESTS |
54 |
171 |
31232000 |
|
|
246571045 |
TLE_Automaton |
E |
Feb. 15, 2024, 5:24 p.m. |
OK |
GNU C++17 (64) |
TESTS |
54 |
171 |
31232000 |
|
|
246619762 |
hhhyh |
E |
Feb. 16, 2024, 5:24 a.m. |
OK |
GNU C++17 (64) |
TESTS |
54 |
171 |
37376000 |
|
|
246613368 |
LXH-cat |
E |
Feb. 16, 2024, 3:52 a.m. |
OK |
GNU C++17 (64) |
TESTS |
54 |
187 |
17203200 |
|
|
246571114 |
clyzszh |
E |
Feb. 15, 2024, 5:25 p.m. |
OK |
GNU C++17 (64) |
TESTS |
54 |
202 |
103936000 |
|
|
246590891 |
kaiboy |
E |
Feb. 15, 2024, 8:27 p.m. |
OK |
GNU C++20 (64) |
TESTS |
54 |
78 |
21708800 |
|
|
246567212 |
-ilya- |
E |
Feb. 15, 2024, 5:03 p.m. |
OK |
GNU C++20 (64) |
TESTS |
54 |
108 |
17715200 |
|
|
246601741 |
ikaurov |
E |
Feb. 15, 2024, 11:39 p.m. |
OK |
GNU C++20 (64) |
TESTS |
54 |
109 |
21401600 |
|
|
246610217 |
Jlyfish |
E |
Feb. 16, 2024, 3 a.m. |
OK |
GNU C++20 (64) |
TESTS |
54 |
124 |
13004800 |
|
|
246576746 |
Fysty |
E |
Feb. 15, 2024, 6:07 p.m. |
OK |
GNU C++20 (64) |
TESTS |
54 |
124 |
19456000 |
|
|
246622242 |
SSerxhs |
E |
Feb. 16, 2024, 5:55 a.m. |
OK |
GNU C++20 (64) |
TESTS |
54 |
124 |
23142400 |
|
|
246560499 |
MyGO_Tomori |
E |
Feb. 15, 2024, 4:27 p.m. |
OK |
GNU C++20 (64) |
TESTS |
54 |
124 |
24985600 |
|
|
246621829 |
koukanni |
E |
Feb. 16, 2024, 5:50 a.m. |
OK |
GNU C++20 (64) |
TESTS |
54 |
124 |
32051200 |
|
|
246615851 |
shenfe1 |
E |
Feb. 16, 2024, 4:30 a.m. |
OK |
GNU C++20 (64) |
TESTS |
54 |
139 |
136704000 |
|
|
246586299 |
FortuneWillWinICPC |
E |
Feb. 15, 2024, 7:36 p.m. |
OK |
GNU C++20 (64) |
TESTS |
54 |
140 |
19763200 |
|
|
246581346 |
santanu021 |
E |
Feb. 15, 2024, 6:46 p.m. |
OK |
Java 21 |
TESTS |
54 |
623 |
28672000 |
|
|
246572152 |
profchi |
E |
Feb. 15, 2024, 5:32 p.m. |
OK |
Java 21 |
TESTS |
54 |
1434 |
83353600 |
|
|
246571972 |
profchi |
E |
Feb. 15, 2024, 5:31 p.m. |
OK |
Java 21 |
TESTS |
54 |
1497 |
82841600 |
|
|
246578407 |
mircea85 |
E |
Feb. 15, 2024, 6:20 p.m. |
OK |
Mono C# |
TESTS |
54 |
1575 |
86220800 |
|
|
246569253 |
plevande |
E |
Feb. 15, 2024, 5:13 p.m. |
OK |
PyPy 3 |
TESTS |
54 |
1669 |
58265600 |
|
|
246567463 |
Little_Sheep_Yawn |
E |
Feb. 15, 2024, 5:04 p.m. |
OK |
PyPy 3-64 |
TESTS |
54 |
467 |
34099200 |
|
|
246578760 |
dishanth0282 |
E |
Feb. 15, 2024, 6:23 p.m. |
OK |
PyPy 3-64 |
TESTS |
54 |
732 |
61747200 |
|
|
246602848 |
codicon |
E |
Feb. 16, 2024, 12:13 a.m. |
OK |
PyPy 3-64 |
TESTS |
54 |
748 |
47820800 |
|
|
246578437 |
yuki_keshiki |
E |
Feb. 15, 2024, 6:20 p.m. |
OK |
PyPy 3-64 |
TESTS |
54 |
748 |
61644800 |
|
|
246567220 |
misorin |
E |
Feb. 15, 2024, 5:03 p.m. |
OK |
PyPy 3-64 |
TESTS |
54 |
795 |
53555200 |
|
|
246560985 |
mymelochan |
E |
Feb. 15, 2024, 4:28 p.m. |
OK |
PyPy 3-64 |
TESTS |
54 |
810 |
71782400 |
|
|
remove filters
Back to search problems