No.758 VVVVV
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Problem Statement
You are given an ordered tree with N vertices rooted at vertex 1.
When performing a DFS on this ordered tree from the root, there are two kinds of moves: "descending from a parent to a child" and "returning from a child to its parent". We call them move A and move B, respectively.
Also, let M be the number of times the move "changes from move A to move B, or from move B to move A" during the DFS of this ordered tree.
Find the number, modulo MOD $10^9 + 7$, of ordered trees with N vertices for which the number of times the move "changes from move A to move B, or from move B to move A" during the DFS is equal to M.
Input
$N$
$a_1\ b_1$
$a_i\ b_i$
$a_{N - 1}\ b_{N - 1}$
The first line gives the number of vertices $N (1 \le N \le 10^5)$.
The following N - 1 lines give the edges; each edge connects vertex $a_i$ and vertex $b_i$ with each other.
$1 \le a_i, b_i \le N$
Output
Output the number of ordered trees modulo MOD $10^9 + 7$.
Sample
Sample 1
Input
5 1 2 2 3 2 4 3 5
Output
6
Writing the DFS moves using A and B,
we get AAABBABB, and the number of times the kind of move changes is 3.
Sample 2
Input
10 1 2 1 3 3 4 3 5 4 6 2 7 5 8 4 9 7 10
Output
1176
Sample 3
Input
30 1 2 2 3 2 4 4 5 3 6 1 7 3 8 3 9 3 10 10 11 8 12 8 13 10 14 10 15 12 16 3 17 5 18 1 19 16 20 13 21 21 22 7 23 7 24 17 25 25 26 21 27 14 28 18 29 23 30
Output
493001124
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
matsu7874