当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6647:Bracket Sequences on Tree

题目描述
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$.

输入解释
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$.
输出解释
For each test case, output the answer in one line.
输入样例
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
输出样例
2
4
8
来自杭电HDUOJ的附加信息
Recommend chendu

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6647

最后修改于 2020-10-25T23:33:08+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
40000/20000MS(Java/Others) 524288/524288K(Java/Others)