A12017 | Vasya and Maximum Matching
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
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$ .
输入格式
The first line contains one integer $n$ ( $1 \le n \le 3 \cdot 10^5$ ) — the number of vertices in the tree.
Each of the next $n − 1$ lines contains two integers $u$ and $v$ ( $1 \le u, v \le n, u \neq v$ ) denoting an edge between vertex $u$ and vertex $v$ . It is guaranteed that these edges form a tree.
Each of the next $n − 1$ lines contains two integers $u$ and $v$ ( $1 \le u, v \le n, u \neq v$ ) denoting an edge between vertex $u$ and vertex $v$ . It is guaranteed that these edges form a tree.
输出格式
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$ .
输入输出样例
输入 #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.
- 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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted