atcoder#NIKKEI20192QUALB. Counting of Trees
Counting of Trees
Score : points
Problem Statement
Given is an integer sequence of elements. Find the number, modulo , of trees with vertices numbered to that satisfy the following condition:
- For every integer from to , the distance between Vertex and Vertex is .
Notes
- A tree of vertices is a connected undirected graph with vertices and edges, and the distance between two vertices are the number of edges in the shortest path between them.
- Two trees are considered different if and only if there are two vertices and such that there is an edge between and in one of those trees and not in the other.
Constraints
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4
0 1 1 2
2
For example, a tree with edges , , and satisfies the condition.
4
1 1 1 1
0
7
0 3 2 1 2 2 1
24