LCRS Transform
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Walk Alone has a binary tree T with n nodes labelled from 1 to n rooted at node 1. Each node u in the tree has at most two children, the left child \ell_{T,u} and the right child r_{T,u}, where \ell_{T,u} denotes the label of the left child and \ell_{T,u}=0 if u does not have a left child, and r_{T,u} similarly. We omit the subscript _T if T is clear from the context. The right child of u exists only if u has a left child.
He once performed an operation named left-child right-sibling (LCRS) transform on the tree for exactly k times. In each operation, he would
  • Visit all vertices in descending order of depth. For each vertex u with two children \ell_u and r_u, remove edge (u, r_u) and let the right child of \ell_u be r_u. It can be shown that \ell_u does not have a right child at this time.
  • For each vertex u with a right child and no left child, i.e., r_u\neq 0 and \ell_u=0, swap \ell_u and r_u.
You can refer to the following code for better understanding.
void dfs(int u) {
  // l[u]/r[u]: The left/right child of node u
  // Recursively visit all children of node u
  if (l[u] != 0) dfs(l[u]);
  if (r[u] != 0) dfs(r[u]);

  if (r[u] != 0) {
    // Here l[u] != 0 because r[u] != 0
    if (l[l[u]] == 0) l[l[u]] = r[u];
    else r[l[u]] = r[u];
    r[u] = 0;
  }
}
void LCRS() {
  dfs(1);
}
However, he forgot what the original tree is like. Now he wants you to tell him the number of different possible initial trees modulo 998\,244\,353. Two trees T_1 and T_2 are considered different if and only if there exists a node u such that (\ell_{T_1,u},r_{T_1,u})\neq (\ell_{T_2,u},r_{T_2,u}).

输入描述:

The first line contains two integers n\ (1\leq n\leq 10^5) and k\ (0 \leq k\leq 10^5), the number of nodes and the number of operations Walk Alone has done, respectively.
The i-th of the next n lines contains two integers \ell_i and r_i\ (0 \leq \ell_i,r_i \leq n), indicating that the left and right child of i in the resulting tree are \ell_i and r_i respectively. If i has no left (right) child, then \ell_i=0\ (r_i=0). It is guaranteed that the given graph is a tree rooted at node 1, and that r_i\neq 0 only if \ell_i\neq 0.

输出描述:

Output an integer indicating the number of possible initial trees modulo 998\,244\,353.
示例1

输入

复制
5 1
2 0
4 3
0 0
5 0
0 0

输出

复制
2
示例2

输入

复制
4 2
2 0
3 0
4 0
0 0

输出

复制
4
示例3

输入

复制
4 2
2 0
3 4
0 0
0 0

输出

复制
0

备注:

In the first example, the two possible trees are illustrated as below.