###name
Bracket Sequences on Tree
###decription
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:
function dfs(int cur, int parent):
print(‘(‘)
for all nxt that cur is adjacent to:
dfs(nxt, cur)
print(‘)’)
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≤t≤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≤n≤10^5)$, the size of tree; then n−1 lines, each consisting of two space-separated integers u, v (1≤u,v≤n, u≠v), denoting an edge.
The sum of n from all test cases does not exceed $3.2×10^6$.
###output
For each test case, output the answer in one line.
###sample input
3
4
1 3
2 3
4 3
5
1 2
2 3
3 4
4 5
5
1 2
2 3
3 4
3 5
###sample output
2
4
8
###toturial
其实很简单,就一个树hash然后树dp就秒掉了,但是由于之前学某博客的树hash,结果冲突掉了,最后看了杨弋的论文才懂了怎么一回事
###code
1 |
|
- 本文作者: fightinggg
- 本文链接: http://fightinggg.github.io/yilia/yilia/PW4Q34.html
- 版权声明: 本博客所有文章除特别声明外,均采用 MIT 许可协议。转载请注明出处!