QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 256 MB مجموع النقاط: 100 الصعوبة: [عرض] قابلة للهجوم ✓

#4240. 树圆

الإحصائيات

给定一棵有 $n$ 个顶点的树,边用 $1$ 到 $n-1$ 的不同整数编号。

定义以 $v$ 为中心、半径为 $r$ 的圆为:在仅保留编号 $\le r$ 的边时,$v$ 所在的连通分量中的所有顶点集合。

你需要回答关于这棵树的若干查询。 每个查询给定 $k$ 个顶点 $v_1, v_2, \dots, v_k$。 你需要求出为每个给定顶点选择一个半径的方法数,使得所有圆互不相交。 换句话说,你需要计算满足 $circle(v_i, r_i) \cap circle(v_j, r_j) = \emptyset$(对于所有 $i \neq j$)的元组 $(r_1, r_2, \dots, r_k)$(其中 $0 \le r_1, r_2, \dots, r_k \le n - 1$)的数量。 由于结果可能非常大,你只需要输出其对 $998\,244\,353$ 取模的结果。

输入格式

第一行包含一个整数 $n$ ($2 \le n \le 300\,000$):给定树的顶点数。 接下来的 $n-1$ 行描述边,每行包含两个整数 $u_i, v_i$ ($1 \le u_i, v_i \le n; u_i \neq v_i$),表示连接顶点 $u_i$ 和 $v_i$ 的边,其编号为 $i$。 保证给定的图是一棵树。 下一行包含一个整数 $q$ ($1 \le q \le n$):查询的数量。 接下来的 $q$ 行描述查询,每行包含一个整数 $k$ ($1 \le k \le n$),以及随后的 $k$ 个不同的整数 $v_1, v_2, \dots, v_k$ ($1 \le v_i \le n$)。 保证所有查询中 $k$ 的总和不超过 $300\,000$。

输出格式

对于每个查询,输出一个整数:满足 $circle(v_i, r_i) \cap circle(v_j, r_j) = \emptyset$(对于所有 $i \neq j$)的元组 $(r_1, r_2, \dots, r_k)$ 的数量,对 $998\,244\,353$ 取模。

样例

样例输入 1

3
1 2
2 3
2
3 1 2 3
2 1 3

样例输出 1

2
4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.