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, numbered from 1 to n . Every vertex is colored in some color, denoted by an integer from 1 to n . A simple path of the tree is called beautiful if: Count the number of the beautiful simple paths of the tree. Note that paths are considered undirected (i. e. the path from x to y is the same as the path from y to x ). The first line contains a single integer t ( 1 <= t <= 10^4 ) -- the number of testcases. The first line of each testcase contains a single integer n ( 2 <= n <= 2 cdot 10^5 ) -- the number of vertices in the tree. The second line contains n integers c_1, c_2, ... , c_n ( 1 <= c_i <= n ) -- the color of each vertex. The i -th of the next n - 1 lines contains two integers v_i and u_i ( 1 <= v_i, u_i <= n ; v_i neq u_i ) -- the i -th edge of the tree. The given edges form a valid tree. The sum of n over all testcases doesn't exceed 2 cdot 10^5 . For each testcase, print a single integer -- the number of the beautiful simple paths of the tree. "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
247989697 |
rainboy |
E |
Feb. 23, 2024, 5:26 p.m. |
OK |
GNU C11 |
TESTS |
37 |
171 |
18432000 |
|
|
248039436 |
liujg |
E |
Feb. 24, 2024, 3:55 a.m. |
OK |
GNU C++17 |
TESTS |
37 |
217 |
15769600 |
|
|
248033054 |
mr.tj.mr |
E |
Feb. 24, 2024, 2:03 a.m. |
OK |
GNU C++17 |
TESTS |
37 |
218 |
14950400 |
|
|
248043774 |
-ve |
E |
Feb. 24, 2024, 4:55 a.m. |
OK |
GNU C++17 |
TESTS |
37 |
218 |
22118400 |
|
|
248046420 |
huangallen |
E |
Feb. 24, 2024, 5:25 a.m. |
OK |
GNU C++17 |
TESTS |
37 |
233 |
14438400 |
|
|
248043040 |
PARTHO_DAS |
E |
Feb. 24, 2024, 4:46 a.m. |
OK |
GNU C++17 |
TESTS |
37 |
233 |
22220800 |
|
|
248015588 |
pkhaustov |
E |
Feb. 23, 2024, 8:46 p.m. |
OK |
GNU C++17 |
TESTS |
37 |
234 |
17408000 |
|
|
248018668 |
dmot |
E |
Feb. 23, 2024, 9:21 p.m. |
OK |
GNU C++17 |
TESTS |
37 |
248 |
23040000 |
|
|
248016794 |
GreatJoN_Umber |
E |
Feb. 23, 2024, 9 p.m. |
OK |
GNU C++17 |
TESTS |
37 |
248 |
31436800 |
|
|
247999826 |
H2J |
E |
Feb. 23, 2024, 6:33 p.m. |
OK |
GNU C++17 |
TESTS |
37 |
249 |
25702400 |
|
|
248029708 |
Mhamad_aboaljood |
E |
Feb. 24, 2024, 12:43 a.m. |
OK |
GNU C++17 |
TESTS |
37 |
249 |
27340800 |
|
|
248034878 |
Sakuya_maid |
E |
Feb. 24, 2024, 2:42 a.m. |
OK |
GNU C++17 (64) |
TESTS |
37 |
218 |
41779200 |
|
|
248026086 |
Arrebol0717 |
E |
Feb. 23, 2024, 11:21 p.m. |
OK |
GNU C++17 (64) |
TESTS |
37 |
233 |
32870400 |
|
|
248033031 |
whdywjd |
E |
Feb. 24, 2024, 2:02 a.m. |
OK |
GNU C++17 (64) |
TESTS |
37 |
233 |
35020800 |
|
|
247987162 |
lkgw |
E |
Feb. 23, 2024, 5:10 p.m. |
OK |
GNU C++17 (64) |
TESTS |
37 |
233 |
36044800 |
|
|
247993232 |
Hirro |
E |
Feb. 23, 2024, 5:49 p.m. |
OK |
GNU C++17 (64) |
TESTS |
37 |
249 |
42496000 |
|
|
247998930 |
SaturdayF |
E |
Feb. 23, 2024, 6:27 p.m. |
OK |
GNU C++17 (64) |
TESTS |
37 |
264 |
29593600 |
|
|
247980643 |
WRuperD |
E |
Feb. 23, 2024, 4:41 p.m. |
OK |
GNU C++17 (64) |
TESTS |
37 |
264 |
56934400 |
|
|
247986380 |
xu826281112 |
E |
Feb. 23, 2024, 5:06 p.m. |
OK |
GNU C++17 (64) |
TESTS |
37 |
265 |
54988800 |
|
|
247994070 |
Hirro |
E |
Feb. 23, 2024, 5:54 p.m. |
OK |
GNU C++17 (64) |
TESTS |
37 |
280 |
37683200 |
|
|
247987378 |
lalaouye |
E |
Feb. 23, 2024, 5:11 p.m. |
OK |
GNU C++17 (64) |
TESTS |
37 |
295 |
53657600 |
|
|
248010815 |
ASN49K |
E |
Feb. 23, 2024, 7:59 p.m. |
OK |
GNU C++20 (64) |
TESTS |
37 |
124 |
28262400 |
|
|
248008747 |
ASN49K |
E |
Feb. 23, 2024, 7:41 p.m. |
OK |
GNU C++20 (64) |
TESTS |
37 |
140 |
28160000 |
|
|
248009448 |
ASN49K |
E |
Feb. 23, 2024, 7:47 p.m. |
OK |
GNU C++20 (64) |
TESTS |
37 |
140 |
28262400 |
|
|
248021932 |
othmaine |
E |
Feb. 23, 2024, 10:06 p.m. |
OK |
GNU C++20 (64) |
TESTS |
37 |
156 |
17920000 |
|
|
248047236 |
NextThread |
E |
Feb. 24, 2024, 5:34 a.m. |
OK |
GNU C++20 (64) |
TESTS |
37 |
170 |
27136000 |
|
|
247987829 |
kaiboy |
E |
Feb. 23, 2024, 5:14 p.m. |
OK |
GNU C++20 (64) |
TESTS |
37 |
170 |
28774400 |
|
|
248042466 |
sjdka |
E |
Feb. 24, 2024, 4:38 a.m. |
OK |
GNU C++20 (64) |
TESTS |
37 |
171 |
18534400 |
|
|
248007690 |
Milan |
E |
Feb. 23, 2024, 7:32 p.m. |
OK |
GNU C++20 (64) |
TESTS |
37 |
171 |
24678400 |
|
|
248040743 |
tamir1 |
E |
Feb. 24, 2024, 4:15 a.m. |
OK |
GNU C++20 (64) |
TESTS |
37 |
171 |
24678400 |
|
|
248035282 |
I_love_GSNQK |
E |
Feb. 24, 2024, 2:50 a.m. |
OK |
GNU C++20 (64) |
TESTS |
37 |
171 |
27136000 |
|
|
248036868 |
0x3F |
E |
Feb. 24, 2024, 3:15 a.m. |
OK |
Go |
TESTS |
37 |
343 |
50585600 |
|
|
248036692 |
0x3F |
E |
Feb. 24, 2024, 3:13 a.m. |
OK |
Go |
TESTS |
37 |
358 |
49664000 |
|
|
248036625 |
0x3F |
E |
Feb. 24, 2024, 3:12 a.m. |
OK |
Go |
TESTS |
37 |
358 |
50585600 |
|
|
248031270 |
sugar2023 |
E |
Feb. 24, 2024, 1:21 a.m. |
OK |
Go |
TESTS |
37 |
545 |
165273600 |
|
|
248045342 |
ajayg3059 |
E |
Feb. 24, 2024, 5:13 a.m. |
OK |
Go |
TESTS |
37 |
607 |
181350400 |
|
|
248045668 |
ajayg3059 |
E |
Feb. 24, 2024, 5:17 a.m. |
OK |
Go |
TESTS |
37 |
685 |
180121600 |
|
|
247984863 |
FierteDeCeylan |
E |
Feb. 23, 2024, 4:58 p.m. |
OK |
Java 21 |
TESTS |
37 |
982 |
120320000 |
|
|
248044358 |
ggghg |
E |
Feb. 24, 2024, 5:02 a.m. |
OK |
Java 21 |
TESTS |
37 |
1029 |
112025600 |
|
|
247978209 |
vijay_panwar12 |
E |
Feb. 23, 2024, 4:34 p.m. |
OK |
Java 21 |
TESTS |
37 |
1434 |
136601600 |
|
|
247985790 |
Eslam_Ahmed |
E |
Feb. 23, 2024, 5:03 p.m. |
OK |
Java 21 |
TESTS |
37 |
1481 |
122572800 |
|
|
248017023 |
Sumitsingh7 |
E |
Feb. 23, 2024, 9:02 p.m. |
OK |
Java 8 |
TESTS |
37 |
966 |
144793600 |
|
|
247986627 |
Eslam_Ahmed |
E |
Feb. 23, 2024, 5:07 p.m. |
OK |
Java 8 |
TESTS |
37 |
1278 |
154009600 |
|
|
248047881 |
tauros |
E |
Feb. 24, 2024, 5:40 a.m. |
OK |
Kotlin 1.9 |
TESTS |
37 |
436 |
28979200 |
|
|
247986764 |
tauros |
E |
Feb. 23, 2024, 5:08 p.m. |
OK |
Kotlin 1.9 |
TESTS |
37 |
811 |
18739200 |
|
|
248047554 |
tauros |
E |
Feb. 24, 2024, 5:37 a.m. |
OK |
Kotlin 1.9 |
TESTS |
37 |
1746 |
49868800 |
|
|
247992724 |
N1KlTA |
E |
Feb. 23, 2024, 5:45 p.m. |
OK |
MS C++ 2017 |
TESTS |
37 |
576 |
18124800 |
|
|
247993080 |
Darisishe |
E |
Feb. 23, 2024, 5:48 p.m. |
OK |
MS C++ 2017 |
TESTS |
37 |
997 |
52326400 |
|
|
248007423 |
OLOGY |
E |
Feb. 23, 2024, 7:29 p.m. |
OK |
PyPy 2 |
TESTS |
37 |
733 |
74649600 |
|
|
248013096 |
OLOGY |
E |
Feb. 23, 2024, 8:21 p.m. |
OK |
PyPy 2 |
TESTS |
37 |
826 |
76288000 |
|
|
248030254 |
OLOGY |
E |
Feb. 24, 2024, 12:56 a.m. |
OK |
PyPy 2 |
TESTS |
37 |
998 |
87961600 |
|
|
248013018 |
OLOGY |
E |
Feb. 23, 2024, 8:20 p.m. |
OK |
PyPy 2 |
TESTS |
37 |
1060 |
93388800 |
|
|
248027811 |
OLOGY |
E |
Feb. 23, 2024, 11:59 p.m. |
OK |
PyPy 2 |
TESTS |
37 |
1060 |
93593600 |
|
|
248030178 |
OLOGY |
E |
Feb. 24, 2024, 12:54 a.m. |
OK |
PyPy 2 |
TESTS |
37 |
1060 |
101273600 |
|
|
248012515 |
OLOGY |
E |
Feb. 23, 2024, 8:15 p.m. |
OK |
PyPy 2 |
TESTS |
37 |
1060 |
102809600 |
|
|
248027828 |
OLOGY |
E |
Feb. 23, 2024, 11:59 p.m. |
OK |
PyPy 2 |
TESTS |
37 |
1092 |
101888000 |
|
|
248028419 |
OLOGY |
E |
Feb. 24, 2024, 12:14 a.m. |
OK |
PyPy 2 |
TESTS |
37 |
1107 |
100454400 |
|
|
247989005 |
yuki_keshiki |
E |
Feb. 23, 2024, 5:21 p.m. |
OK |
PyPy 3-64 |
TESTS |
37 |
857 |
101171200 |
|
|
248013535 |
abcsumits |
E |
Feb. 23, 2024, 8:25 p.m. |
OK |
PyPy 3-64 |
TESTS |
37 |
904 |
78131200 |
|
|
248031606 |
liupengsay |
E |
Feb. 24, 2024, 1:29 a.m. |
OK |
PyPy 3-64 |
TESTS |
37 |
950 |
120320000 |
|
|
247986129 |
misorin |
E |
Feb. 23, 2024, 5:05 p.m. |
OK |
PyPy 3-64 |
TESTS |
37 |
1029 |
148684800 |
|
|
248036298 |
hxu10 |
E |
Feb. 24, 2024, 3:07 a.m. |
OK |
PyPy 3-64 |
TESTS |
37 |
1044 |
141516800 |
|
|
248041267 |
dhruvokay |
E |
Feb. 24, 2024, 4:22 a.m. |
OK |
PyPy 3-64 |
TESTS |
37 |
1123 |
124211200 |
|
|
247983437 |
JinYuManTang |
E |
Feb. 23, 2024, 4:52 p.m. |
OK |
PyPy 3-64 |
TESTS |
37 |
1138 |
134963200 |
|
|
248014434 |
eunsoo0607 |
E |
Feb. 23, 2024, 8:34 p.m. |
OK |
PyPy 3-64 |
TESTS |
37 |
1169 |
147456000 |
|
|
248024795 |
gardengnome |
E |
Feb. 23, 2024, 10:56 p.m. |
OK |
PyPy 3-64 |
TESTS |
37 |
1216 |
126156800 |
|
|
248020119 |
fisk |
E |
Feb. 23, 2024, 9:40 p.m. |
OK |
PyPy 3-64 |
TESTS |
37 |
1232 |
122982400 |
|
|
248007471 |
OLOGY |
E |
Feb. 23, 2024, 7:30 p.m. |
OK |
Python 2 |
TESTS |
37 |
1700 |
86220800 |
|
|
248030231 |
OLOGY |
E |
Feb. 24, 2024, 12:56 a.m. |
OK |
Python 2 |
TESTS |
37 |
1731 |
118886400 |
|
|
248007676 |
OLOGY |
E |
Feb. 23, 2024, 7:32 p.m. |
OK |
Python 2 |
TESTS |
37 |
1777 |
85913600 |
|
|
248028460 |
OLOGY |
E |
Feb. 24, 2024, 12:15 a.m. |
OK |
Python 2 |
TESTS |
37 |
1918 |
118988800 |
|
|
248008668 |
OLOGY |
E |
Feb. 23, 2024, 7:40 p.m. |
OK |
Python 2 |
TESTS |
37 |
1965 |
123392000 |
|
|
247981556 |
shade34 |
E |
Feb. 23, 2024, 4:45 p.m. |
OK |
Python 3 |
TESTS |
37 |
1544 |
83558400 |
|
|
remove filters
Back to search problems