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
Yousef has a rooted tree(^{\text{∗}}) consisting of exactly (n) vertices, which is rooted at vertex (1). You would like to give Yousef an array (a) of length (n), where each (a_i) ((1 \le i \le n)) can either be (1) or (2) . Let (s_u) denote the sum of (a_v) where vertex (v) is in the subtree(^{\text{†}}) of vertex (u). Yousef considers the tree special if all the values in (s) are pairwise distinct (i.e., all subtree sums are unique). Your task is to help Yousef count the number of different arrays (a) that result in the tree being special . Two arrays (b) and (c) are different if there exists an index (i) such that (b_i \neq c_i). As the result can be very large, you should print it modulo (10^9 + 7). (^{\text{∗}})A tree is a connected undirected graph with (n - 1) edges. (^{\text{†}})The subtree of a vertex (v) is the set of all vertices that pass through (v) on a simple path to the root. Note that vertex (v) is also included in the set. The first line contains an integer (t) ((1 \le t \le 10^4)) — the number of test cases. Each test case consists of several lines. The first line of the test case contains an integer (n) ((2 \le n \le 2 \cdot 10^5)) — the number of vertices in the tree. Then (n−1) lines follow, each of them contains two integers (u) and (v) ((1 \le u,v \le n, u \ne v)) which describe a pair of vertices connected by an edge. It is guaranteed that the given graph is a tree and has no loops or multiple edges. It is guaranteed that the sum of (n) over all test cases doesn't exceed (2 \cdot 10^5). For each test case, print one integer (x) — the number of different arrays (a) that result in the tree being special , modulo (10^9 + 7). The tree given in the fifth test case: |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
323713414 |
og.kostya |
F |
June 10, 2025, 5:12 a.m. |
OK |
C# 13 |
TESTS |
12 |
265 |
52531200 |
|
|
|
323620875 |
AzzyZhe |
F |
June 9, 2025, 11:04 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
12 |
124 |
9932800 |
|
|
|
323638749 |
hnust_wangkang |
F |
June 9, 2025, 1:16 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
12 |
139 |
40140800 |
|
|
|
323679460 |
edga |
F |
June 9, 2025, 6:37 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
12 |
140 |
12492800 |
|
|
|
323648886 |
librarykeeper |
F |
June 9, 2025, 2:30 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
12 |
140 |
21913600 |
|
|
|
323694375 |
utkal.lenka1 |
F |
June 9, 2025, 10:55 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
12 |
140 |
24883200 |
|
|
|
323624962 |
v1296 |
F |
June 9, 2025, 11:35 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
12 |
155 |
2969600 |
|
|
|
323694306 |
gulatibhavishya |
F |
June 9, 2025, 10:53 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
12 |
155 |
4096000 |
|
|
|
323716403 |
lahoax |
F |
June 10, 2025, 5:46 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
12 |
155 |
12492800 |
|
|
|
323697497 |
whiteedu |
F |
June 10, 2025, 12:47 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
12 |
155 |
14848000 |
|
|
|
323677597 |
goulthen |
F |
June 9, 2025, 6:22 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
12 |
155 |
22732800 |
|
|
|
323713231 |
temp_swufe |
F |
June 10, 2025, 5:10 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
12 |
108 |
15155200 |
|
|
|
323622052 |
MR_NoSolution |
F |
June 9, 2025, 11:13 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
12 |
124 |
13721600 |
|
|
|
323615650 |
kuailedetongnian |
F |
June 9, 2025, 10:22 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
12 |
124 |
21196800 |
|
|
|
323620255 |
CUST_GIAO_ZE |
F |
June 9, 2025, 10:59 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
12 |
124 |
31641600 |
|
|
|
323696114 |
sujal1234 |
F |
June 9, 2025, 11:58 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
12 |
125 |
6348800 |
|
|
|
323627204 |
amogh_jalan |
F |
June 9, 2025, 11:52 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
12 |
125 |
9728000 |
|
|
|
323689577 |
siddhesh.o4 |
F |
June 9, 2025, 8:54 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
12 |
139 |
8089600 |
|
|
|
323640981 |
milk81 |
F |
June 9, 2025, 1:32 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
12 |
139 |
28876800 |
|
|
|
323646675 |
ssk_I |
F |
June 9, 2025, 2:15 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
12 |
139 |
30515200 |
|
|
|
323620937 |
LuOH3_ |
F |
June 9, 2025, 11:04 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
12 |
140 |
4812800 |
|
|
|
323687767 |
emni_o |
F |
June 9, 2025, 8:23 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
12 |
125 |
8192000 |
|
|
|
323717902 |
WhiteBread |
F |
June 10, 2025, 6:02 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
12 |
125 |
9830400 |
|
|
|
323617533 |
NeuralG |
F |
June 9, 2025, 10:37 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
12 |
139 |
33689600 |
|
|
|
323707971 |
cefegent |
F |
June 10, 2025, 4:02 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
12 |
140 |
4915200 |
|
|
|
323657089 |
radhekrishn04 |
F |
June 9, 2025, 3:35 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
12 |
140 |
5120000 |
|
|
|
323657053 |
Archit_Modi_21 |
F |
June 9, 2025, 3:34 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
12 |
140 |
5120000 |
|
|
|
323607237 |
akramdevstuffs |
F |
June 9, 2025, 9:23 a.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
12 |
140 |
5632000 |
|
|
|
323690703 |
MohammadTaghizade |
F |
June 9, 2025, 9:17 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
12 |
140 |
6451200 |
|
|
|
323649712 |
tarun02185 |
F |
June 9, 2025, 2:37 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
12 |
140 |
7270400 |
|
|
|
323655725 |
kumar_eklavya |
F |
June 9, 2025, 3:24 p.m. |
OK |
C++23 (GCC 14-64, msys2) |
TESTS |
12 |
140 |
8192000 |
|
|
|
323607646 |
_MShadow_ |
F |
June 9, 2025, 9:26 a.m. |
OK |
Java 21 |
TESTS |
12 |
578 |
83763200 |
|
|
|
323664317 |
WrongAnswerOnTestCase2 |
F |
June 9, 2025, 4:33 p.m. |
OK |
Java 21 |
TESTS |
12 |
608 |
64716800 |
|
|
|
323659080 |
_CHEEMS_ |
F |
June 9, 2025, 3:51 p.m. |
OK |
Java 21 |
TESTS |
12 |
733 |
130560000 |
|
|
|
323689310 |
messi_10db |
F |
June 9, 2025, 8:49 p.m. |
OK |
Java 21 |
TESTS |
12 |
999 |
57446400 |
|
|
|
323660127 |
chefnav35 |
F |
June 9, 2025, 3:59 p.m. |
OK |
Java 21 |
TESTS |
12 |
1062 |
79769600 |
|
|
|
323617635 |
sreecharanreddypacharla |
F |
June 9, 2025, 10:38 a.m. |
OK |
Java 21 |
TESTS |
12 |
1093 |
34201600 |
|
|
|
323673466 |
matchstick97 |
F |
June 9, 2025, 5:46 p.m. |
OK |
Java 21 |
TESTS |
12 |
1265 |
101580800 |
|
|
|
323692634 |
Sumitsingh7 |
F |
June 9, 2025, 10:03 p.m. |
OK |
Java 8 |
TESTS |
12 |
280 |
64614400 |
|
|
|
323690732 |
satyams_9001 |
F |
June 9, 2025, 9:18 p.m. |
OK |
Java 8 |
TESTS |
12 |
280 |
64614400 |
|
|
|
323659251 |
ShengY |
F |
June 9, 2025, 3:52 p.m. |
OK |
Java 8 |
TESTS |
12 |
436 |
55603200 |
|
|
|
323618124 |
seeforty4040 |
F |
June 9, 2025, 10:42 a.m. |
OK |
PyPy 3-64 |
TESTS |
12 |
218 |
27545600 |
|
|
|
323604288 |
minuki646 |
F |
June 9, 2025, 9:05 a.m. |
OK |
PyPy 3-64 |
TESTS |
12 |
265 |
32665600 |
|
|
|
323629171 |
aam2k6 |
F |
June 9, 2025, 12:07 p.m. |
OK |
PyPy 3-64 |
TESTS |
12 |
468 |
30003200 |
|
|
|
323717694 |
guptaprakhar_01 |
F |
June 10, 2025, 6 a.m. |
OK |
PyPy 3-64 |
TESTS |
12 |
468 |
35942400 |
|
|
|
323673742 |
Vanekss |
F |
June 9, 2025, 5:48 p.m. |
OK |
PyPy 3-64 |
TESTS |
12 |
483 |
49459200 |
|
|
|
323628686 |
rishabj_45 |
F |
June 9, 2025, 12:04 p.m. |
OK |
PyPy 3-64 |
TESTS |
12 |
484 |
26726400 |
|
|
|
323630639 |
Pulkit_gupta |
F |
June 9, 2025, 12:18 p.m. |
OK |
PyPy 3-64 |
TESTS |
12 |
530 |
31539200 |
|
|
|
323652102 |
the_seal |
F |
June 9, 2025, 2:54 p.m. |
OK |
PyPy 3-64 |
TESTS |
12 |
561 |
43827200 |
|
|
|
323672109 |
_Cobalt_ |
F |
June 9, 2025, 5:34 p.m. |
OK |
PyPy 3-64 |
TESTS |
12 |
562 |
35225600 |
|
|
|
323634689 |
nik1009 |
F |
June 9, 2025, 12:47 p.m. |
OK |
PyPy 3-64 |
TESTS |
12 |
608 |
51200000 |
|
|
|
323639905 |
huangjiajing |
F |
June 9, 2025, 1:24 p.m. |
OK |
Python 3 |
TESTS |
12 |
530 |
46694400 |
|
|
|
323639872 |
chatterjee_sid |
F |
June 9, 2025, 1:24 p.m. |
OK |
Python 3 |
TESTS |
12 |
530 |
60416000 |
|
|
|
323640015 |
huangjiajing |
F |
June 9, 2025, 1:25 p.m. |
OK |
Python 3 |
TESTS |
12 |
546 |
46592000 |
|
|
|
323640151 |
chatterjee_sid |
F |
June 9, 2025, 1:26 p.m. |
OK |
Python 3 |
TESTS |
12 |
546 |
63692800 |
|
|
|
323617134 |
rcd |
F |
June 9, 2025, 10:34 a.m. |
OK |
Python 3 |
TESTS |
12 |
640 |
47308800 |
|
|
|
323689928 |
anejmeldeen |
F |
June 9, 2025, 9:01 p.m. |
OK |
Python 3 |
TESTS |
12 |
718 |
78233600 |
|
|
|
323612959 |
staircase2418 |
F |
June 9, 2025, 10:05 a.m. |
OK |
Python 3 |
TESTS |
12 |
1108 |
89907200 |
|
|
|
323614283 |
bqn |
F |
June 9, 2025, 10:13 a.m. |
OK |
Rust 2021 |
TESTS |
12 |
124 |
22220800 |
|
|
remove filters
Back to search problems