A14264 | Diameter Cuts
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an integer $k$ and an undirected tree, consisting of $n$ vertices.
The length of a simple path (a path in which each vertex appears at most once) between some pair of vertices is the number of edges in this path. A diameter of a tree is the maximum length of a simple path between all pairs of vertices of this tree.
You are about to remove a set of edges from the tree. The tree splits into multiple smaller trees when the edges are removed. The set of edges is valid if all the resulting trees have diameter less than or equal to $k$ .
Two sets of edges are different if there is an edge such that it appears in only one of the sets.
Count the number of valid sets of edges modulo $998\,244\,353$ .
The length of a simple path (a path in which each vertex appears at most once) between some pair of vertices is the number of edges in this path. A diameter of a tree is the maximum length of a simple path between all pairs of vertices of this tree.
You are about to remove a set of edges from the tree. The tree splits into multiple smaller trees when the edges are removed. The set of edges is valid if all the resulting trees have diameter less than or equal to $k$ .
Two sets of edges are different if there is an edge such that it appears in only one of the sets.
Count the number of valid sets of edges modulo $998\,244\,353$ .
输入格式
The first line contains two integers $n$ and $k$ ( $2 \le n \le 5000$ , $0 \le k \le n - 1$ ) — the number of vertices of the tree and the maximum allowed diameter, respectively.
Each of the next $n-1$ lines contains a description of an edge: two integers $v$ and $u$ ( $1 \le v, u \le n$ , $v \neq u$ ).
The given edges form a tree.
Each of the next $n-1$ lines contains a description of an edge: two integers $v$ and $u$ ( $1 \le v, u \le n$ , $v \neq u$ ).
The given edges form a tree.
输出格式
Print a single integer — the number of valid sets of edges modulo $998\,244\,353$ .
输入输出样例
输入 #1
4 3 1 2 1 3 1 4
输出 #1
8
输入 #2
2 0 1 2
输出 #2
1
输入 #3
6 2 1 6 2 4 2 6 3 6 5 6
输出 #3
25
输入 #4
6 3 1 2 1 5 2 3 3 4 5 6
输出 #4
29
In the first example the diameter of the given tree is already less than or equal to $k$ . Thus, you can choose any set of edges to remove and the resulting trees will have diameter less than or equal to $k$ . There are $2^3$ sets, including the empty one.
In the second example you have to remove the only edge. Otherwise, the diameter will be $1$ , which is greater than $0$ .
Here are the trees for the third and the fourth examples:

In the second example you have to remove the only edge. Otherwise, the diameter will be $1$ , which is greater than $0$ .
Here are the trees for the third and the fourth examples:

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted