|
||||||||||
Bracket Sequences on TreeTime Limit: 40000/20000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 779 Accepted Submission(s): 215 Problem Description Cuber QQ knows about DFS on an undirected tree, he's sure that you are familiar with it too. In case you are not, Cuber QQ is delighted to share with you a snippet of pseudo code:
You might notice that Cuber QQ print a "(" when entering a node, and a ")" when leaving a node. So when he finishes this DFS, in his console, he will see a bracket sequence of length $2n$, where $n$ is the number of vertices in the tree. Obviously, if the tree is undirected and the nodes are unlabelled (meaning that all the nodes are treated equally), you can get a lot of different bracket sequences when you do the DFS. There are two reasons accounting for this. Firstly, when you are at cur, you can follow any permutation of the nodes that cur is adjacent to when you visit nxt. Secondly, the entrance to the tree, that is the root, is undeterministic when you start your DFS. So Cuber QQ couldn't help wondering how many distinct bracket sequences he can get possibly. As the answer can be very large, output it modulo $998~244~353$. Input The first line of the input consists of one integer $t$ ($1 \le t \le 10^5$), which is the number of the test cases. For each test case, the tree is given in a standard format, which you might be very familiar with: first line $n$ ($1 \le n \le 10^5$), the size of tree; then $n-1$ lines, each consisting of two space-separated integers $u$, $v$ ($1 \le u, v \le n$, $u \ne v$), denoting an edge. The sum of $n$ from all test cases does not exceed $3.2 \times 10^6$. Output For each test case, output the answer in one line. Sample Input
Sample Output
Source | ||||||||||
|