#!/usr/bin/env python3 # Solution idea: per node, determine the number of subtrees of each size that contain that node # This can be computed using a DFS and convolving the values of the children nodes # Read input M, d, total, answer, tree = 10 ** 9 + 7, [0], [0] * (n := int(input())), [[1] for _ in range(n)], [[] for i in range(n)] for a, b in [(i, int(input())) for i in range(1, n)]: tree[a].append(b), tree[b].append(a) # Construct DFS ordering without recursion for i in range(n): [(d.append(w), tree[w].remove(d[i])) for w in tree[d[i]]] # Convolve the solutions per node in DFS order for v in reversed(d): for w in tree[v]: answer[v] += [0] * len(answer[w]) for i1, c1 in [(i1, c1) for i1, c1 in reversed(list(enumerate(answer[v]))) if c1 != 0]: for i2, c2 in enumerate(answer[w]): answer[v][i1 + i2 + 1] += c1 * c2 for i, c in enumerate(answer[v]): total[i] = (total[i] + c) % M print(*total)