1236 : 生成树计数
- 时间限制Time Limit
- 1 秒Sec
- 内存限制Memory Limit
- 256 兆MB
- 提交次数Submitted
- 26 次Times
- 通过次数Solved
- 14 次Times
标准评测 Standard
从标准输入读入,结果写到标准输出。评测将输出拆成 token,与标准答案逐项比较,不按整段逐字节比对。
Read from standard input and write to standard output. The judge splits the output into tokens and compares them with the official answer; it does not compare raw bytes.
| 比对Compare | token 相同即通过。中间的空格、制表符、换行可多可少。Matching tokens pass. Extra spaces, tabs, or newlines between them are ignored. |
|---|---|
| 不同则错Differs | token 个数或内容不同即错误。23 与 2 3、02 与 2、2.0 与 2 均视为不同。A different token count or value is wrong. 23 vs 2 3, 02 vs 2, and 2.0 vs 2 all differ. |
| 输入Input | 标准输入,格式见题面。Standard input; format as in the statement. |
| 输出Output | 标准输出。Standard output. |
| 时间与内存Time and memory | 记这一份程序的 CPU 时间和内存峰值。题目上的时间限制、内存限制就是这一份的上限。The record is this program’s CPU time and peak memory. The limits on the problem apply to this one run. |
题目描述Description
给定一个有 \(n\) 个节点的树,初始节点编号为从 \(1\) 到 \(n\),再给定一个长度为 \(n-1\) 节点序列,我们将按照序列的顺序对树进行操作。
对于每个操作,如果当前要操作的节点是 \(x\),首先创建一个新节点,编号为 \(x+n\)。对于任意整数 \(i\in [1,n]\),如果边 \((x,i)\) 存在:
如果节点 \(i+n\) 不存在,我们连接 \((x+n,i)\)。
如果节点 \(i+n\) 存在(在这种情况下,边 \((x,i+n)\) 总是存在的),我们连接 \((x+n,i+n)\) 并删除边 \((x,i+n)\)。
对于每个操作后得到的新图,请计算其生成树的数量,并对 \(998244353\) 取模。
输入格式Input
第一行包含一个整数 \(n \; (1 \le n \le 5000)\),表示树的大小。
接下来的 \(n-1\) 行,每行包含两个数字 \(u\) 和 \(v\;(1\le u,v\le n)\),表示树中的边 \((u,v)\)。保证输入形成一棵合法的树。
最后一行包含 \(n-1\) 个不同的数字 \(b_i\;(1 \le b_i \le n)\),表示按顺序进行操作的节点序列。
输出格式Output
输出 \(n-1\) 行,第 \(i\) 行输出一个整数表示执行完第 \(i\) 个操作后图中生成树的数量,答案对 \(998244353\) 取模。
样例Sample
出题Author
SYSU
题目到此结束End of problem