CF1032F.Vasya and Maximum Matching
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya has got a tree consisting of n vertices. He wants to delete some (possibly zero) edges in this tree such that the maximum matching in the resulting graph is unique. He asks you to calculate the number of ways to choose a set of edges to remove.
A matching in the graph is a subset of its edges such that there is no vertex incident to two (or more) edges from the subset. A maximum matching is a matching such that the number of edges in the subset is maximum possible among all matchings in this graph.
Since the answer may be large, output it modulo 998244353.
瓦西娅有一棵由 n 个顶点构成的树。他希望删除该树中的一些(可能为零条)边,使得所得图的最大匹配是唯一的。请你计算选择待删除边集的方法数。
图中的一个匹配是指其边集的一个子集,满足其中任意顶点至多与该子集中的两条(或更多)边关联。一个最大匹配是指在该图所有匹配中,边数最多的匹配。
由于答案可能很大,请将结果对 998244353 取模后输出。
输入格式
The first line contains one integer n (1≤n≤3⋅105) — the number of vertices in the tree.
Each of the next n−1 lines contains two integers u and v (1≤u,v≤n,u=v) denoting an edge between vertex u and vertex v. It is guaranteed that these edges form a tree.
第一行包含一个整数 n(1≤n≤3⋅105)——树中顶点的数量。
接下来的 n−1 行,每行包含两个整数 u 和 v(1≤u,v≤n, u=v),表示顶点 u 与顶点 v 之间的一条边。保证这些边构成一棵树。
输出格式
Print one integer — the number of ways to delete some (possibly empty) subset of edges so that the maximum matching in the resulting graph is unique. Print the answer modulo 998244353.
输出一个整数——表示删除某个(可能为空的)边子集的方式数目,使得剩余图中的最大匹配是唯一的。答案对 998244353 取模。
输入输出样例
输入#1
4 1 2 1 3 1 4
输出#1
4
输入#2
4 1 2 2 3 3 4
输出#2
6
输入#3
1
输出#3
1
说明/提示
Possible ways to delete edges in the first example:
- delete (1,2) and (1,3).
- delete (1,2) and (1,4).
- delete (1,3) and (1,4).
- delete all edges.
Possible ways to delete edges in the second example:
- delete no edges.
- delete (1,2) and (2,3).
- delete (1,2) and (3,4).
- delete (2,3) and (3,4).
- delete (2,3).
- delete all edges.
第一个示例中删除边的可能方式:
- 删除边 (1,2) 和 (1,3)。
- 删除边 (1,2) 和 (1,4)。
- 删除边 (1,3) 和 (1,4)。
- 删除所有边。
第二个示例中删除边的可能方式:
- 不删除任何边。
- 删除边 (1,2) 和 (2,3)。
- 删除边 (1,2) 和 (3,4)。
- 删除边 (2,3) 和 (3,4)。
- 删除边 (2,3)。
- 删除所有边。
输入解题思路,AI测评打分。不知道怎么写?