{"raw_statement":[{"iden":"statement","content":"给出一棵 $n$ 个节点的树，每个点有点权 $a_v$。定义一棵树的一个子连通块为一个树中点的**非空集合**，满足这些点在树上形成一个连通块。定义子连通块 $S$ 的权值为 $\\prod_{v\\in S}(a_v+|S|)$。求所有子连通块的权值之和对 $U^V$ 取模。"},{"iden":"input","content":"第一行，三个正整数 $n,U,V$，分别表示节点个数，以及模数（$U^V$）。\n\n第二行，$n-1$ 个正整数 $f_2,f_3,\\dots,f_n$，分别表示以 $1$ 节点为根节点的情况下第 $i$ 个点的父亲节点。\n\n第三行，$n$ 个非负整数 $a_i$，表示每个点的点权。"},{"iden":"output","content":"一行，一个正整数，表示所有子联通块的权值之和，对 $U^V$ 取模。"},{"iden":"note","content":"### 样例解释\n\n对于样例 $1$，以下子连通块的权值分别是：\n\n* $\\{1\\}$：$(1+1)=2$；\n* $\\{2\\}$：$(2+1)=3$；\n* $\\{3\\}$：$(3+1)=4$；\n* $\\{1,2\\}$：$(1+2)\\times(2+2)=12$；\n* $\\{1,3\\}$：$(1+2)\\times(3+2)=15$；\n* $\\{1,2,3\\}$：$(1+3)\\times(2+3)\\times(3+3)=120$。\n\n总和为 $2+3+4+12+15+120=156$，对 $10^6$ 取模后为 $156$。\n\n### 数据范围\n\n**本题采用捆绑测试。**\n\n| $\\text{Subtask}$ | 特殊性质 | $\\text{Score}$ |\n|:--:|:--:|:--:|\n| $1$ | $n\\leq10$ | $5$ |\n| $2$ | $n\\leq150$ | $8$ |\n| $3$ | $n\\leq500$ | $11$ |\n| $4$ | $U=2,V=1$ | $7$ |\n| $5$ | $V=1$ | $23$ |\n| $6$ | $U\\mid a_i$ | $23$ |\n| $7$ | 无特殊限制 | $23$ |\n\n对于 $100\\%$ 的数据：$1\\leq n\\leq2000$，$1\\leq f_i<i$，$2\\leq U\\leq10$，$1\\leq V\\leq6$，$0\\leq a_i< U^V$。"}],"translated_statement":null,"sample_group":[["3 10 6\n1 1\n1 2 3","156"],["11 4 6\n1 1 2 3 4 4 4 5 6 7\n325 190 400 325 380 165 334 400 80 171 340","678"]],"show_order":[],"formal_statement":null,"simple_statement":null,"has_page_source":false}