CF1146F.Leaf Partition
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a rooted tree with n nodes, labeled from 1 to n. The tree is rooted at node 1. The parent of the i-th node is pi. A leaf is node with no children. For a given set of leaves L, let f(L) denote the smallest connected subgraph that contains all leaves L.
You would like to partition the leaves such that for any two different sets x,y of the partition, f(x) and f(y) are disjoint.
Count the number of ways to partition the leaves, modulo 998244353. Two ways are different if there are two leaves such that they are in the same set in one way but in different sets in the other.
给你一棵有 n 个节点的有根树,节点编号为 1 到 n,根节点为节点 1。第 i 个节点的父节点为 pi。叶子节点是指没有子节点的节点。对于给定的叶子节点集合 L,记 f(L) 为包含所有 L 中叶子节点的最小连通子图。
你希望将所有叶子节点划分为若干个集合,使得该划分中任意两个不同的集合 x 和 y 满足:f(x) 与 f(y) 互不相交(即二者无公共节点)。
求满足条件的叶子节点划分方案数,对 998244353 取模。若存在两个叶子节点,在一种方案中属于同一集合,而在另一种方案中属于不同集合,则认为这两种方案不同。
输入格式
The first line contains an integer n (2≤n≤200000) — the number of nodes in the tree.
The next line contains n−1 integers p2,p3,…,pn (1≤pi<i).
第一行包含一个整数 n(2≤n≤200000)——树中节点的数量。
接下来的一行包含 n−1 个整数 p2,p3,…,pn(1≤pi<i)。
输出格式
Print a single integer, the number of ways to partition the leaves, modulo 998244353.
输出一个整数,表示划分叶子节点的方案数,对 998244353 取模。
输入输出样例
输入#1
5 1 1 1 1
输出#1
12
输入#2
10 1 2 3 4 5 6 7 8 9
输出#2
1
说明/提示
In the first example, the leaf nodes are 2,3,4,5. The ways to partition the leaves are in the following image 
In the second example, the only leaf is node 10 so there is only one partition. Note that node 1 is not a leaf.
在第一个例子中,叶子节点为 2,3,4,5。叶子节点的划分方式如下图所示:
在第二个例子中,唯一的叶子节点是节点 10,因此只存在一种划分方式。注意,节点 1 并非叶子节点。
输入解题思路,AI测评打分。不知道怎么写?