首页 > 试题广场 >

Endless Pallet

[编程题]Endless Pallet
There is a tree formed by N nodes. Initially, all the nodes are in white color. If there is at least one white node on the tree, Ash will randomly choose a path on the tree and dye all the nodes in the path black. Otherwise, Ash will stop dyeing and go home.

Given the tree, can you calculate the expected number of the paths Ash choose?

There are paths in total, that is, path from u to v and path from v to u are the same. It is okay to choose a path with no white node, but Ash will stop dyeing immediately when there are no white nodes on the tree.

输入描述:
The input starts with one line containing exactly one integer T, which is the number of test cases.

Each test case starts with one line containing exactly one integer N, indicating the size of the tree.

Then followed by N lines, each consists of 2 numbers ui, vi, indicating the i-th edge of the tree is between ui and vi.
- 1 ≤ T ≤ 15.
- 1 ≤ N ≤ 50.
- 1 ≤ ui, vi ≤ n.



输出描述:
For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the expected number of the paths Ash choose.

In order to avoid floating point arithmetic, you are supposed to output y modulo 998244353, that means if the answer is equal to , you should output .
示例1

输入

3
1
2
1 2
3
2 3
1 3

输出

Case #1: 1
Case #2: 2
Case #3: 698771050
头像 Tweetuzki
发表于 2019-11-29 21:26:08
题目传送门 算法:min-max 容斥、树上背包、NTT。 题意简述 有一棵 个点的树。一开始所有点都是白色,每次操作会随机选择 条路径中的一条,将路径上所有点染黑。求所有点都被染黑的期望操作数。 。多组数据。对 取模。 题解 套路性地,我们使用 min-max 容斥。 如果我们把树画出来,并 展开全文