A13111 | Tree Elimination
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya has a tree with $n$ vertices numbered from $1$ to $n$ , and $n - 1$ edges numbered from $1$ to $n - 1$ . Initially each vertex contains a token with the number of the vertex written on it.
Vasya plays a game. He considers all edges of the tree by increasing of their indices. For every edge he acts as follows:
- If both endpoints of the edge contain a token, remove a token from one of the endpoints and write down its number.
- Otherwise, do nothing.
The result of the game is the sequence of numbers Vasya has written down. Note that there may be many possible resulting sequences depending on the choice of endpoints when tokens are removed.
Vasya has played for such a long time that he thinks he exhausted all possible resulting sequences he can obtain. He wants you to verify him by computing the number of distinct sequences modulo $998\,244\,353$ .
Vasya plays a game. He considers all edges of the tree by increasing of their indices. For every edge he acts as follows:
- If both endpoints of the edge contain a token, remove a token from one of the endpoints and write down its number.
- Otherwise, do nothing.
The result of the game is the sequence of numbers Vasya has written down. Note that there may be many possible resulting sequences depending on the choice of endpoints when tokens are removed.
Vasya has played for such a long time that he thinks he exhausted all possible resulting sequences he can obtain. He wants you to verify him by computing the number of distinct sequences modulo $998\,244\,353$ .
输入格式
The first line contains a single integer $n$ ( $2 \leq n \leq 2 \cdot 10^5$ ) — the number of vertices of the tree.
The next $n - 1$ lines describe edges of the tree. The $i$ -th of these lines contains two integers $u_i, v_i$ ( $1 \leq u_i, v_i \leq n$ ) — endpoints of the edge with index $i$ . It is guaranteed that the given graph is indeed a tree.
The next $n - 1$ lines describe edges of the tree. The $i$ -th of these lines contains two integers $u_i, v_i$ ( $1 \leq u_i, v_i \leq n$ ) — endpoints of the edge with index $i$ . It is guaranteed that the given graph is indeed a tree.
输出格式
Print a single integer — the number of distinct sequences modulo $998\,244\,353$ .
输入输出样例
输入 #1
5 1 2 1 3 1 4 1 5
输出 #1
5
输入 #2
7 7 2 7 6 1 2 7 5 4 7 3 5
输出 #2
10
In the first sample case the distinct sequences are $(1), (2, 1), (2, 3, 1), (2, 3, 4, 1), (2, 3, 4, 5)$ .
Int the second sample case the distinct sequences are $(2, 6, 5, 3), (2, 6, 5, 7), (2, 6, 7, 2), (2, 6, 7, 5), (2, 7, 3), (2, 7, 5), (7, 1, 3), (7, 1, 5), (7, 2, 3), (7, 2, 5)$ .
Int the second sample case the distinct sequences are $(2, 6, 5, 3), (2, 6, 5, 7), (2, 6, 7, 2), (2, 6, 7, 5), (2, 7, 3), (2, 7, 5), (7, 1, 3), (7, 1, 5), (7, 2, 3), (7, 2, 5)$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted