#P11039. 【MX-X3-T6】「RiOI-4」TECHNOPOLIS 2085

    ID: 11395 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>O2优化虚树组合数学Prüfer 序列梦熊比赛

【MX-X3-T6】「RiOI-4」TECHNOPOLIS 2085

Background

Original link: https://oier.team/problems/X3G


(The image is from a Phigros song illustration. Please contact for removal if needed.)

Ah~ ah~ ah yi~ ah yi~ oh→ ah↑ ah↓ ah~ um~ ai ai↑ ai oh ai um~ oh ah~ love↖ love↑ love↗ love↑ love↑ ah~ ah~ ah yi~ ah yi~ ah→ ah↑ ah↓ ah~ um um↓ um↓ di de di de wu↑ ~~ du← du↖️ du↑ du↗️ du→ du↘️ du↓

You are right, but this is a Dream Bear weekly contest problem, not a place for the setter to "generate electricity", so you need to solve a graph theory problem.

Problem Description

By convention, lcaG(u,v)\operatorname{lca}_G(u,v) denotes the lowest common ancestor of nodes with labels u,vu,v in a labeled rooted tree GG. You are given a rooted tree TT with root label 11, size nn, and node labels 1n1\sim n, as well as a node set SS of size mm. You need to find how many distinct labeled rooted trees TT' of size nn with node labels 1n1\sim n satisfy that for any u,vSu,v\in S, we have $\operatorname{lca}_T(u,v)=\operatorname{lca}_{T'}(u,v)$.

Output the answer modulo 998244353998\,244\,353.

We say two labeled rooted trees of size nn are different if and only if at least one of the following holds:

  • Their root nodes are different.
  • There exists an edge that appears in one tree but not in the other.

Input Format

The first line contains two positive integers n,mn,m.

The second line contains n1n-1 positive integers p2,p3,,pnp_2,p_3,\cdots,p_n, where pip_i is the parent label of node ii for i=2ni=2\sim n.

The last line contains mm positive integers, indicating the labels of the selected nodes in the set SS.

Output Format

One line with one integer, the answer modulo 998244353998\,244\,353.

5 3
1 1 2 2
3 4 5

1
5 3
1 1 2 2
2 3 4
8
20 10
20 8 7 16 3 15 1 10 17 3 13 15 1 17 1 14 14 8 4
3 7 10 19 15 13 4 6 18 5
553508927

Hint

Sample Explanation #1

Only the tree that is exactly the same as TT satisfies the requirement.

Sample Explanation #2

For sample 2, all 88 valid pp arrays are as follows (the root has pi=0p_i=0):

$\{0,1,1,2,1\},\{0,1,1,2,2\},\{0,1,1,2,3\},\{0,1,1,2,4\},$
$\{0,1,1,5,2\},\{0,5,1,2,1\},\{0,1,5,2,1\},\{5,1,1,2,0\}$。

Constraints

This problem uses bundled testdata.

Subtask Score nn\le mm\le
11 77 1010
22 1818 200200
33 2222 10510^5
44 1717 10610^6 1010
55 3636 10610^6

For 100%100\% of the data, 2mn1062\le m\le n\le 10^6. It is guaranteed that the input pp describes a labeled rooted tree, and SS describes a set of nodes.

Translated by ChatGPT 5