CF981H.K Paths
NOI/NOI+/CTSC
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree of n vertices. You are to select k (not necessarily distinct) simple paths in such a way that it is possible to split all edges of the tree into three sets: edges not contained in any path, edges that are a part of exactly one of these paths, and edges that are parts of all selected paths, and the latter set should be non-empty.
Compute the number of ways to select k paths modulo 998244353.
The paths are enumerated, in other words, two ways are considered distinct if there are such i (1≤i≤k) and an edge that the i-th path contains the edge in one way and does not contain it in the other.
给你一棵包含 n 个顶点的树。你需要选择 k 条(不一定互不相同)简单路径,使得可以将树的所有边划分为如下三类:
- 不属于任何一条所选路径的边;
- 恰好属于所选路径中某一条的边;
- 属于所有所选路径的边(即这 k 条路径的公共边),且该类边集非空。
请计算满足条件的 k 条路径的选择方案数,对 998244353 取模。
路径是有编号的,即:若存在某个 i(1≤i≤k)以及某条边,使得在一种方案中第 i 条路径包含该边、而在另一种方案中不包含,则这两种方案被视为不同。
输入格式
The first line contains two integers n and k (1≤n,k≤105) — the number of vertices in the tree and the desired number of paths.
The next n−1 lines describe edges of the tree. Each line contains two integers a and b (1≤a,b≤n, a=b) — the endpoints of an edge. It is guaranteed that the given edges form a tree.
第一行包含两个整数 n 和 k(1≤n,k≤105)—— 分别表示树中顶点的数量和期望的路径数量。
接下来的 n−1 行描述树的边。每行包含两个整数 a 和 b(1≤a,b≤n,a=b)—— 表示一条边的两个端点。保证所给的边构成一棵树。
输出格式
Print the number of ways to select k enumerated not necessarily distinct simple paths in such a way that for each edge either it is not contained in any path, or it is contained in exactly one path, or it is contained in all k paths, and the intersection of all paths is non-empty.
As the answer can be large, print it modulo 998244353.
输出满足以下条件的选取 k 条(带编号、不一定互异)简单路径的方法数:对每条边,它要么不被任何路径包含,要么恰好被其中一条路径包含,要么被全部 k 条路径包含;且这 k 条路径的交集非空。
由于答案可能很大,请对 998244353 取模后输出。
输入输出样例
输入#1
3 2 1 2 2 3
输出#1
7
输入#2
5 1 4 1 2 3 4 5 2 1
输出#2
10
输入#3
29 29 1 2 1 3 1 4 1 5 5 6 5 7 5 8 8 9 8 10 8 11 11 12 11 13 11 14 14 15 14 16 14 17 17 18 17 19 17 20 20 21 20 22 20 23 23 24 23 25 23 26 26 27 26 28 26 29
输出#3
125580756
说明/提示
In the first example the following ways are valid:
- ((1,2),(1,2)),
- ((1,2),(1,3)),
- ((1,3),(1,2)),
- ((1,3),(1,3)),
- ((1,3),(2,3)),
- ((2,3),(1,3)),
- ((2,3),(2,3)).
In the second example k=1, so all n⋅(n−1)/2=5⋅4/2=10 paths are valid.
In the third example, the answer is ≥998244353, so it was taken modulo 998244353, don't forget it!
在第一个例子中,以下方案是合法的:
- ((1,2),(1,2)),
- ((1,2),(1,3)),
- ((1,3),(1,2)),
- ((1,3),(1,3)),
- ((1,3),(2,3)),
- ((2,3),(1,3)),
- ((2,3),(2,3)).
在第二个例子中,k=1,因此所有 n⋅(n−1)/2=5⋅4/2=10 条路径均合法。
在第三个例子中,答案 ≥998244353,因此需对 998244353 取模,请勿遗漏!
输入解题思路,AI测评打分。不知道怎么写?