QOJ.ac

QOJ

Time Limit: 8 s Memory Limit: 512 MB Total points: 100

#10354. 黑白树

Statistics

给定一棵 $n$ 个点的树,每个点有 $50\%$ 的概率为黑点,$50\%$ 的概率为白点。

给定正整数 $m$,等概率随机选出一个边集(即每条边有 $50\%$ 的概率在边集中),记边集大小为 $x$。若对于边集中的每条边,都满足这条边两侧的黑点个数不同,则得分为 $m^x$,否则得分为 $0$。

你需要求出期望得分。

有多组数据。

输入格式

第一行一个正整数 $t$ 表示数据组数。

每组数据第一行两个正整数 $n$,$m$。接下来 $n-1$ 行每行两个正整数 $u$,$v$ 表示一条边。

输出格式

对于每组数据,输出一行一个整数表示期望得分$ \times 2^{2n-1}$对$998244353$取模的结果。

样例数据

样例输入

2
3 5
1 2
2 3
10 23333333
3 1
4 2
6 7
8 6
2 5
3 6
10 1
9 7
1 2

样例输出

158
167850015

子任务

对于10%的数据,$n \leq 10$。

对于20%的数据,$n \leq 20$。

对于30%的数据,$n \leq 200$。

对于40%的数据,$n \leq 1000$。

对于50%的数据,$n \leq 3000$。

对于60%的数据,$n \leq 10000$。

对于70%的数据,$n \leq 15000$。

对于100%的数据,$t \leq 5$,$2 \leq n \leq 20000$,$\sum n \leq 70000$,$1 \leq m < 998244353$,$1 \leq u,v \leq n$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.