CF2190D.Prufer Vertex

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For a tree TT with n≥2n \ge 2 vertices, consider the standard process for generating its Prufer sequence. We repeatedly perform the following steps until only two vertices remain:

  • Select the leaf with the smallest label;
  • Remove it from the tree.

It is known that vertex nn is always one of the two remaining vertices. Let vv be the other remaining vertex. We define the Prufer vertex of TT as P(T)=vP(T) = v.

You are given a forest with nn vertices and mm edges. Let kk be the number of connected components in this forest, and let their sizes be s1,s2,…,sks_1, s_2, \ldots, s_k. It is known that there are exactly nk−2∏i=1ksin^{k - 2} \prod\limits_{i=1}^k s_i ways to add edges to the forest so that it becomes a single tree.

For each vv (1≤v<n1 \le v \lt n), calculate how many of these ways result in a tree TT satisfying P(T)=vP(T) = v.

Since the answers can be large, print them modulo 998 244 353998\,244\,353.

对于一棵包含 n≥2n \ge 2 个顶点的树 TT,考虑其 Prüfer 序列 的标准生成过程:我们不断重复以下步骤,直到树中仅剩两个顶点:

  • 选取标号最小的叶子顶点;
  • 将其从树中删除。

已知顶点 nn 总是最后剩余的两个顶点之一。设另一个剩余顶点为 vv。我们定义树 TT 的 Prüfer 顶点为 P(T)=vP(T) = v。

给定一个包含 nn 个顶点和 mm 条边的森林。设该森林包含 kk 个连通分量,各连通分量的大小依次为 s1,s2,…,sks_1, s_2, \ldots, s_k。已知恰好有 nk−2∏i=1ksin^{k - 2} \prod\limits_{i=1}^k s_i 种方式向该森林添加边,使其成为一棵单一的树。

对每个 vv(1≤v<n1 \le v < n),计算有多少种这样的加边方式能产生一棵满足 P(T)=vP(T) = v 的树 TT。

由于答案可能很大,请对 998 244 353998\,244\,353 取模后输出。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5, 0≤m≤n−10 \le m \le n - 1) — the number of vertices and edges in the forest, respectively.

The next mm lines of each test case contain two integers uu and vv (1≤u,v≤n,u≠v1 \le u, v \le n, u \neq v), describing an edge between vertices uu and vv. It is guaranteed that these edges form a forest (that is, the graph is acyclic).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,0≤m≤n−10 \le m \le n - 1),分别表示森林中的顶点数和边数。

每个测试用例接下来的 mm 行,每行包含两个整数 uu 和 vv(1≤u,v≤n1 \le u, v \le n,u≠vu \neq v),表示顶点 uu 与顶点 vv 之间存在一条边。保证这些边构成一个森林(即该图无环)。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print n−1n - 1 integers on a single line. The ii-th integer should be the number of ways to add edges to the forest so that it becomes a tree TT satisfying P(T)=iP(T) = i, modulo 998 244 353998\,244\,353.

对于每个测试用例,在一行中输出 n−1n - 1 个整数。其中第 ii 个整数表示:向该森林中添加边使其成为一棵树 TT,且满足 P(T)=iP(T) = i 的方案数,对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    3
    3 0
    5 4
    4 2
    3 4
    1 2
    4 5
    6 3
    1 6
    6 4
    2 1

    输出#1

    1 2 
    0 0 0 1 
    12 0 1 6 5

说明/提示

In the first example, there are no edges in the forest, and there are 33 ways to complete it to a tree. One of them is to add edges (1,2)(1, 2) and (1,3)(1, 3). There are 22 leaves: vertex 22 and 33. Since 22 has a smaller label, it gets deleted from the tree, and only two vertices remain: 11 and 33. Therefore, the Prufer vertex of this tree is 11.

In the third example, the forest is shown below:

Suppose we add edges (3,5)(3, 5) and (3,1)(3, 1) to complete it to a tree TT. It is going to look like this:

It can be shown that P(T)=1P(T) = 1.

在第一个例子中,森林中没有边,将其补全为一棵树共有 33 种方式。其中一种是添加边 (1,2)(1, 2) 和 (1,3)(1, 3)。此时树中有 22 个叶子节点:顶点 22 和 33。由于 22 的标号更小,它将从树中被删除,剩余两个顶点为 11 和 33。因此,该树的 Prüfer 编码顶点为 11。

在第三个例子中,森林如下图所示:

假设我们添加边 (3,5)(3, 5) 和 (3,1)(3, 1) 将其补全为一棵树 TT,则该树形如:

可以证明,P(T)=1P(T) = 1。

输入解题思路,AI测评打分。不知道怎么写?

首页