import algorithm, future, macros, math, sequtils, sets, strutils, tables macro unpack(rhs: seq, cnt: static[int]): auto = let t = genSym(); result = quote do:(let `t` = `rhs`;()) if NimMinor <= 17: for i in 0..>=`(n: var int, m: int) = n = n shr m proc `?=`(n: var SomeNumber, m: SomeNumber) = n = max(n, m) proc newSeq2[T](n1, n2: Natural): seq[seq[T]] = newSeqWith(n1, newSeq[T](n2)) proc newSeq3[T](n1, n2, n3: Natural): seq[seq[seq[T]]] = newSeqWith(n1, newSeqWith(n2, newSeq[T](n3))) # -------------------------------------------------- # const P = 10 ^ 9 + 7 var (N, K) = input(int, 2) var edge = newseq2[int](N + 1, 0) for i in 1 .. N - 1: var (a, b) = input(int, 2) inc a; inc b; edge[a].add(b) edge[b].add(a) proc dfs(v: int, p: int): seq[int] = result = @[1] for u in edge[v]: if u == p: continue var subtree = dfs(u, v) var A = result.len() var B = subtree.len() var newResult = newseq[int](A + B - 1) for i in 0 .. A - 1: for j in 0 .. B - 1: newResult[i + j] += (result[i] * subtree[j]) mod P newResult[i + j] %= P result = newResult result.add(1) echo dfs(1, 0)[K]