Count DFS Tree

시간 제한1초메모리 제한2048 MB

요약
모든 잎이 깊이 K에 있는 n개 노드 트리에서 DFS 반환 수열의 서로 다른 가짓수를 구하고, M개 질의의 값을 곱해 출력한다.
난이도

어려움10점 중 9점

유형
조합론, 동적 계획법, 수학
정답자
아직 제출이 없습니다

문제

You are currently studying a tree traversal algorithm called the Depth First Search (DFS). Suppose you have a rooted tree of nn nodes (numbered from 11 to nn) with a depth of KK (numbered from 11 to KK). The root (the node at depth 11) is located at node 11. All leaves are located at the same depth, that is, at depth KK. Node ii has an array of children nodes c_ic\_i, which could be empty if ii is a leaf node. The pseudocode of the algorithm is presented as follows.

DFS(u, depth):
  let res be an empty array
  append depth to res

  for each v in c[u]:
    let D be an array initialized with DFS(v, depth + 1)
    for each x in D:
      append x to res

return res

Consider the trees in the following illustration. The return values of DFS(1, 1) for the tree on the left and the tree on the right are \[1,2,3,3,3]\[1, 2, 3, 3, 3] and \[1,2,3,2,3]\[1, 2, 3, 2, 3], respectively.

Denote f_K(n)f\_K(n) as the number of distinct return values of DFS(1, 1) across all trees consisting of nn nodes and all leaves are located in depth KK. You are given MM integers: A_1,A_2,…,A_MA\_1, A\_2, \dots , A\_M. Determine the value of f_K(A_1)×f_K(A_2)×⋯×f_K(A_M)f\_K(A\_1) \times f\_K(A\_2) \times \cdots \times f\_K(A\_M). As the answer can be very large, find the answer modulo 998,244,353998\\, 244\\, 353.

입력

The first line consists of two integers KK MM (1≤K,M≤100,0001 ≤ K, M ≤ 100\\, 000).

The following line consists of MM integers A_iA\_i (K≤A_i≤200,000K ≤ A\_i ≤ 200\\, 000).

출력

Output a single integer representing the value of f_K(A_1)×f_K(A_2)×⋯×f_K(A_M)f\_K(A\_1) \times f\_K(A\_2) \times \cdots \times f\_K(A\_M) modulo 998,244,353998\\, 244\\, 353.

예제2

  1. 예제 1

    입력
    3 2
    5 6
    
    예상 출력
    6
    
  2. 예제 2

    입력
    100000 1
    200000
    
    예상 출력
    269130693