Operating on the Tree
题号:NC209392
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

This problem is inspired by problem G(Operating on the Graph). So you need to read the statement of it in order to solve this problem.

You are given a tree with n vertices. Assume p is a permutation from 0 to n-1. We define a function f(p) as follows:

Assume the given tree is the input graph of problem G, and p is the input operator sequence. f(p) is the number of operations satisfying the condition: When doing the i-th operation, there is at least one vertex belongs to group o_i.

Let S be the set of all possible permutation from 0 to n-1. Please calculate .

输入描述:

The first line contains one integer t () --- the number of test cases.

Each test contains two lines. The first line contains one integer n representing the number of vertices in the given tree (). The second line contains n - 1 non-negative integers . It indicates that the i-th edge of the tree connects vertices i and a_i ().

The sum of n across the test cases doesn't exceed .

输出描述:

For each test, output one line containing one integer in the range  representing the answer.
示例1

输入

复制
3
4
0 1 2
4
0 1 1
2
0

输出

复制
48
60
2

说明

In the first test, the three edges of the tree are (0 - 1), (1 - 2), (2 - 3). If p = [0, 1, 2, 3], there is at least one vertex belong to o_i only when you do the first operation and the third operation. So f([0,1,2,3]) is 2. In fact, no matter what permutation p is, f(p) is always 2 for this graph. So the answer of the first test is 4! \times 2 = 48.