시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 512 MB111100.000%

## 문제

Carol and David are playing a game. There is a rooted binary tree (each vertex has either 0 or 2 children) and an integer $k$. Depth of the vertex is its distance from the root. There is an ordered pair of integers in each leave. Elements of the pairs are between $0$ and $k - 1$ inclusive.

Let $E$ denote the set of internal (non-leave) vertices with even height and $O$ the set of internal vertices with odd height. For each vertex in $E$ Carol marks one of it children. The set of vertices to mark is Carol's strategy. There are $2^{|E|}$ possible strategies for Carol. David does the same thing with vertices in $O$. Therefore he has $2^{|O|}$ possible strategies. We consider only pure strategies in this problem.

A token is placed in the root and moved repeatedly from a vertex to its marked child until it arrives at a leave. Let $(c, d)$ be the pair of integers in this leave. Carol receives the payout of $c$ and David receives the payout of $d$.

A pair of strategies form a Nash equilibrium if neither of the players can get a better payout for himself by changing his strategy while the opponents strategy stays the same.

You are given the tree but not given the pairs of integers in the leaves. There are $k^{2L}$ ways to choose the ordered pairs in the leaves, where $L$ is the number of leaves. Count sum of the number of pairs of strategies which form a Nash equilibrium over all possible ways choose the pairs in the leaves.

Output the correct answer modulo 998244353. Formally, if the actual answer is $y$ and your answer is $x$, it will be considered correct if $-2^{63} \leq x < 2^{63}$ and $x-y$ is divisible by 998244353.

## 입력

The first line contains two integers $n$ and $k$ ($3 \leq n < 5000, 1 \leq k \leq 20$), the number of vertices in the tree and the upper bound on the elements of the pairs in the leaves.

The second line contains $n - 1$ integers $p_i$ ($0 \leq p_i < i$). $i$-th of them (counting from one) describes an edge between vertices $p_i$ and $i$. Every integer occurs either zero or two times among $p_i$.

## 출력

Print a single integer --- the answer to the problem modulo 998244353.

## 예제 입력 1

3 3
0 0


## 예제 출력 1

108


## 예제 입력 2

5 1
0 0 1 1


## 예제 출력 2

4


## 예제 입력 3

17 20
0 1 2 0 1 2 4 7 4 7 3 8 5 3 5 8


## 예제 출력 3

465216081


## 힌트

Notes there are $3^4$ ways to assign pairs to leaves, $2$ possible strategies for Carol and $1$ possible strategy for David (he doesn't get to choose anything, therefore this strategy is somewhat degenerate). If the Carol's payout in the leaves are the same both of her strategies form a Nash equilibrium with the David's unique strategy, otherwise only the strategy which marks the leave with the higher payout does. There are $3 \cdot 3^2$ assignments with equal Carol's payouts and $6 \cdot 3^2$ with different payouts. The answer is $27 \cdot 2 + 54 = 108$.