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 with n vertices. Each vertex i has a value a_i associated with it. Let us root the tree at some vertex v . The vertex v is called a distinctive root if the following holds: in all paths that start at v and end at some other node, all the values encountered are distinct. Two different paths may have values in common but a single path must have all distinct values. Find the number of distinctive roots in the tree. The first line of the input contains a single integer n ( 1 <= n <= 2 cdot10^5 ) -- the number of vertices in the tree. The next line contains n space-separated integers a_1, a_2, ... , a_n ( 1 <= a_i <= 10^9 ). The following n-1 lines each contain two space-separated integers u and v ( 1 <= u , v <= n ), denoting an edge from u to v . It is guaranteed that the edges form a tree. Print a single integer -- the number of distinctive roots in the tree. In the first example, 1 , 2 and 5 are distinctive roots. '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
103834941 |
zjjws |
E |
Jan. 8, 2021, 11:07 p.m. |
OK |
GNU C++11 |
TESTS |
105 |
187 |
31232000 |
|
2500 |
103839569 |
little_brush |
E |
Jan. 9, 2021, 2:08 a.m. |
OK |
GNU C++11 |
TESTS |
105 |
187 |
32870400 |
|
2500 |
103842283 |
zswzswzswzsw |
E |
Jan. 9, 2021, 3:27 a.m. |
OK |
GNU C++11 |
TESTS |
106 |
217 |
92364800 |
|
2500 |
103845840 |
zswzswzswzsw |
E |
Jan. 9, 2021, 4:51 a.m. |
OK |
GNU C++11 |
TESTS |
107 |
233 |
36352000 |
|
2500 |
103845878 |
zswzswzswzsw |
E |
Jan. 9, 2021, 4:52 a.m. |
OK |
GNU C++11 |
TESTS |
107 |
234 |
82022400 |
|
2500 |
103810807 |
prabowo |
E |
Jan. 8, 2021, 5:03 p.m. |
OK |
GNU C++11 |
TESTS |
101 |
265 |
36352000 |
|
2500 |
103838537 |
Cornflakes |
E |
Jan. 9, 2021, 1:30 a.m. |
OK |
GNU C++11 |
TESTS |
105 |
265 |
38400000 |
|
2500 |
103849113 |
XG21 |
E |
Jan. 9, 2021, 5:53 a.m. |
OK |
GNU C++11 |
TESTS |
107 |
280 |
43110400 |
|
2500 |
103810680 |
AoLiGei |
E |
Jan. 8, 2021, 5:02 p.m. |
OK |
GNU C++11 |
TESTS |
101 |
327 |
32665600 |
|
2500 |
103830047 |
Komeiji_Green |
E |
Jan. 8, 2021, 8:49 p.m. |
OK |
GNU C++11 |
TESTS |
105 |
327 |
82227200 |
|
2500 |
103804889 |
liyh98 |
E |
Jan. 8, 2021, 4:28 p.m. |
OK |
GNU C++14 |
TESTS |
101 |
311 |
29388800 |
|
2500 |
103807171 |
Orange_gunwookim |
E |
Jan. 8, 2021, 4:32 p.m. |
OK |
GNU C++14 |
TESTS |
101 |
327 |
43110400 |
|
2500 |
103829373 |
TranLeHiep |
E |
Jan. 8, 2021, 8:35 p.m. |
OK |
GNU C++14 |
TESTS |
104 |
342 |
32460800 |
|
2500 |
103813419 |
wifiiii |
E |
Jan. 8, 2021, 5:19 p.m. |
OK |
GNU C++14 |
TESTS |
102 |
358 |
28979200 |
|
2500 |
103838978 |
SANJIN |
E |
Jan. 9, 2021, 1:50 a.m. |
OK |
GNU C++14 |
TESTS |
105 |
358 |
40243200 |
|
2500 |
103826396 |
Ahoora |
E |
Jan. 8, 2021, 7:41 p.m. |
OK |
GNU C++14 |
TESTS |
104 |
358 |
43724800 |
|
2500 |
103810470 |
SuperJ6 |
E |
Jan. 8, 2021, 5:01 p.m. |
OK |
GNU C++14 |
TESTS |
101 |
405 |
28979200 |
|
2500 |
103817956 |
MarZwEins |
E |
Jan. 8, 2021, 6 p.m. |
OK |
GNU C++14 |
TESTS |
103 |
405 |
38707200 |
|
2500 |
103816107 |
MarZwEins |
E |
Jan. 8, 2021, 5:42 p.m. |
OK |
GNU C++14 |
TESTS |
103 |
436 |
38707200 |
|
2500 |
103845223 |
playf |
E |
Jan. 9, 2021, 4:38 a.m. |
OK |
GNU C++14 |
TESTS |
107 |
451 |
142028800 |
|
2500 |
103817347 |
0375w |
E |
Jan. 8, 2021, 5:54 p.m. |
OK |
GNU C++17 |
TESTS |
103 |
280 |
43417600 |
|
2500 |
103824676 |
key.gal |
E |
Jan. 8, 2021, 7:15 p.m. |
OK |
GNU C++17 |
TESTS |
104 |
311 |
39526400 |
|
2500 |
103842664 |
11231123 |
E |
Jan. 9, 2021, 3:36 a.m. |
OK |
GNU C++17 |
TESTS |
106 |
312 |
25804800 |
|
2500 |
103840267 |
11231123 |
E |
Jan. 9, 2021, 2:30 a.m. |
OK |
GNU C++17 |
TESTS |
105 |
326 |
47411200 |
|
2500 |
103803970 |
WA_King |
E |
Jan. 8, 2021, 4:26 p.m. |
OK |
GNU C++17 |
TESTS |
101 |
342 |
23756800 |
|
2500 |
103814388 |
lucasturci |
E |
Jan. 8, 2021, 5:27 p.m. |
OK |
GNU C++17 |
TESTS |
103 |
342 |
27648000 |
|
2500 |
103833716 |
hiphop-nigdy-stop |
E |
Jan. 8, 2021, 10:25 p.m. |
OK |
GNU C++17 |
TESTS |
105 |
343 |
35328000 |
|
2500 |
103811747 |
kshitij_sodani |
E |
Jan. 8, 2021, 5:08 p.m. |
OK |
GNU C++17 |
TESTS |
101 |
358 |
21504000 |
|
2500 |
103837167 |
Siyuan |
E |
Jan. 9, 2021, 12:42 a.m. |
OK |
GNU C++17 |
TESTS |
105 |
358 |
33280000 |
|
2500 |
103827994 |
couplefire |
E |
Jan. 8, 2021, 8:06 p.m. |
OK |
GNU C++17 |
TESTS |
104 |
358 |
43110400 |
|
2500 |
103824656 |
kaiboy |
E |
Jan. 8, 2021, 7:15 p.m. |
OK |
GNU C++17 (64) |
TESTS |
104 |
249 |
30515200 |
|
2500 |
103844097 |
Zap |
E |
Jan. 9, 2021, 4:10 a.m. |
OK |
GNU C++17 (64) |
TESTS |
106 |
280 |
40345600 |
|
2500 |
103812080 |
LayCurse |
E |
Jan. 8, 2021, 5:10 p.m. |
OK |
GNU C++17 (64) |
TESTS |
101 |
311 |
151961600 |
|
2500 |
103814434 |
nishant403 |
E |
Jan. 8, 2021, 5:27 p.m. |
OK |
GNU C++17 (64) |
TESTS |
103 |
327 |
48742400 |
|
2500 |
103815658 |
kefaa2 |
E |
Jan. 8, 2021, 5:38 p.m. |
OK |
GNU C++17 (64) |
TESTS |
103 |
358 |
48435200 |
|
2500 |
103813558 |
natsugiri |
E |
Jan. 8, 2021, 5:20 p.m. |
OK |
GNU C++17 (64) |
TESTS |
102 |
358 |
72294400 |
|
2500 |
103817757 |
rip |
E |
Jan. 8, 2021, 5:57 p.m. |
OK |
GNU C++17 (64) |
TESTS |
103 |
374 |
135884800 |
|
2500 |
103842124 |
ykx |
E |
Jan. 9, 2021, 3:23 a.m. |
OK |
GNU C++17 (64) |
TESTS |
106 |
389 |
59084800 |
|
2500 |
103805310 |
ykx |
E |
Jan. 8, 2021, 4:29 p.m. |
OK |
GNU C++17 (64) |
TESTS |
101 |
405 |
59084800 |
|
2500 |
103840945 |
PurpleCrayon |
E |
Jan. 9, 2021, 2:50 a.m. |
OK |
GNU C++17 (64) |
TESTS |
106 |
405 |
67686400 |
|
2500 |
103823636 |
Dukkha |
E |
Jan. 8, 2021, 7 p.m. |
OK |
Java 11 |
TESTS |
104 |
1325 |
31948800 |
|
2500 |
103830934 |
subhamdtu |
E |
Jan. 8, 2021, 9:11 p.m. |
OK |
Java 8 |
TESTS |
105 |
998 |
60006400 |
|
2500 |
103832604 |
polyakoff |
E |
Jan. 8, 2021, 9:52 p.m. |
OK |
Java 8 |
TESTS |
105 |
1715 |
146739200 |
|
2500 |
103829916 |
subhamdtu |
E |
Jan. 8, 2021, 8:47 p.m. |
OK |
Java 8 |
TESTS |
105 |
2667 |
268390400 |
|
2500 |
103803387 |
Tlatoani |
E |
Jan. 8, 2021, 4:25 p.m. |
OK |
Kotlin |
TESTS |
101 |
1528 |
73625600 |
|
2500 |
103827180 |
sh1194 |
E |
Jan. 8, 2021, 7:54 p.m. |
OK |
PyPy 3 |
TESTS |
104 |
1076 |
86323200 |
|
2500 |
103826721 |
sh1194 |
E |
Jan. 8, 2021, 7:46 p.m. |
OK |
PyPy 3 |
TESTS |
104 |
1106 |
76390400 |
|
2500 |
103819086 |
at_f |
E |
Jan. 8, 2021, 6:11 p.m. |
OK |
PyPy 3 |
TESTS |
103 |
1107 |
76492800 |
|
2500 |
103826538 |
sh1194 |
E |
Jan. 8, 2021, 7:43 p.m. |
OK |
PyPy 3 |
TESTS |
104 |
1122 |
77107200 |
|
2500 |
103827484 |
sh1194 |
E |
Jan. 8, 2021, 7:58 p.m. |
OK |
PyPy 3 |
TESTS |
104 |
1122 |
86220800 |
|
2500 |
103827028 |
sh1194 |
E |
Jan. 8, 2021, 7:51 p.m. |
OK |
PyPy 3 |
TESTS |
104 |
1122 |
86528000 |
|
2500 |
103827341 |
sh1194 |
E |
Jan. 8, 2021, 7:56 p.m. |
OK |
PyPy 3 |
TESTS |
104 |
1122 |
86630400 |
|
2500 |
103826827 |
sh1194 |
E |
Jan. 8, 2021, 7:48 p.m. |
OK |
PyPy 3 |
TESTS |
104 |
1123 |
86323200 |
|
2500 |
remove filters
Back to search problems