CF1799H.Tree Cutting
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a tree with n vertices.
A hero k times do the following operation:
- Choose some edge.
- Remove it.
- Take one of the two remaining parts and delete it.
- Write the number of vertices in the remaining part.
You are given an initial tree and the a sequence of written numbers. Find the number of ways to make operations such that the written numbers are equal to the given numbers. Due to the answer can be big, find it by modulo 998244353. Two ways are considered different, if on some operation edge or remaining part are selected differently.
你被给定一棵包含 n 个顶点的树。
一位英雄执行 k 次如下操作:
- 选择某条边;
- 删除该边;
- 从剩余的两个连通分量中任选其一并删除;
- 将剩余连通分量中的顶点数写下来。
你被给定初始树以及一个已写出的数字序列。请计算执行上述操作的方式数目,使得所写出的数字序列恰好等于给定序列。由于答案可能很大,请对 998244353 取模。若在某次操作中所选的边或所保留的连通分量不同,则认为两种方式不同。
输入格式
The first line contains a single integer n (2≤n≤5000) — the number of vertices.
Each of the next n−1 lines contains two integers s, f (1≤s,f≤n, s=f) — description of edge (s,f).
Next line contains a single integer k (1≤k≤min(6,n−1)) — the number of operations.
Next line contains k integers s1,s2,…,sk (n>s1>s2>…>sk≥1) — written numbers.
第一行包含一个整数 n(2≤n≤5000)——顶点的数量。
接下来的 n−1 行,每行包含两个整数 s、f(1≤s,f≤n,s=f)——表示一条边 (s,f)。
下一行包含一个整数 k(1≤k≤min(6,n−1))——操作次数。
再下一行包含 k 个整数 s1,s2,…,sk(n>s1>s2>…>sk≥1)——所写的数字。
输出格式
Print a single integer — the answer to the problem by modulo 998244353.
输出一个整数——该问题的答案对 998244353 取模的结果。
输入输出样例
输入#1
3 1 2 2 3 2 2 1
输出#1
4
输入#2
7 2 1 3 2 4 1 5 3 6 4 7 4 2 4 2
输出#2
2
输入#3
7 1 2 1 3 1 4 2 5 3 6 4 7 1 2
输出#3
3
输入#4
7 1 2 1 3 1 4 2 5 3 6 4 7 4 6 5 2 1
输出#4
24
输入#5
8 1 2 2 3 3 4 3 5 3 6 3 7 3 8 2 7 4
输出#5
0
说明/提示
In the first test there are four possible ways to make operations:
- Remove the edge (1,2) and delete vertex 1. Remove the edge (2,3) and delete vertex 2.
- Remove the edge (1,2) and delete vertex 1. Remove the edge (3,2) and delete vertex 3.
- Remove the edge (3,2) and delete vertex 3. Remove the edge (1,2) and delete vertex 1.
- Remove the edge (3,2) and delete vertex 3. Remove the edge (2,1) and delete vertex 2.
In the second test there are two possible ways to make operations:
- Remove the edge (4,1) and delete the part with vertex 4. Remove the edge (2,3) and delete the part with vertex 2.
- Remove the edge (4,1) and delete the part with vertex 4. Remove the edge (3,2) and delete the part with vertex 3.
在第一个测试中,共有四种可能的操作方式:
- 移除边 (1,2) 并删除顶点 1;移除边 (2,3) 并删除顶点 2。
- 移除边 (1,2) 并删除顶点 1;移除边 (3,2) 并删除顶点 3。
- 移除边 (3,2) 并删除顶点 3;移除边 (1,2) 并删除顶点 1。
- 移除边 (3,2) 并删除顶点 3;移除边 (2,1) 并删除顶点 2。
在第二个测试中,共有两种可能的操作方式:
- 移除边 (4,1) 并删除包含顶点 4 的连通分量;移除边 (2,3) 并删除包含顶点 2 的连通分量。
- 移除边 (4,1) 并删除包含顶点 4 的连通分量;移除边 (3,2) 并删除包含顶点 3 的连通分量。
输入解题思路,AI测评打分。不知道怎么写?