##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
4
5 1 2 2 3 3 4 4 5
4 1 2 2 3 2 4
5 1 2 1 3 1 4 1 5
6 1 2 2 3 3 4 3 5 3 6
28
8
10
26
You are given a tree with vertices numbered from to .
A subset of vertices is called good if for every two distinct vertices , there exists a vertex such that .
Compute the number of good subsets , modulo .
This tree is a simple path . For example, is good, because for any two distinct vertices , at least one of or has different distances to them, so . On the other hand, is not good, because vertices and have the same distance to , so , and there is no other vertex in to distinguish them.
This tree has a branching at vertex (edges , , ). For example, is good, since every pair of vertices can be distinguished using either or . However, is not good, because vertices and have the same distance to , so .