atcoder#AGC056F. [AGC056F] Degree Sequence in DFS Order
[AGC056F] Degree Sequence in DFS Order
Score : points
Problem Statement
Given are integers and . Find the number of integer sequences that can be generated as follows, modulo .
- Provide an undirected connected graph with vertices and edges. Here, may not contain self-loops, but may contain multi-edges.
- Perform DFS on and let be the degree of the -th vertex to be visited. More accurately, execute the pseudo-code below to get .
a = empty array
dfs(v):
visited[v]=True
a.append(degree[v])
for u in g[v]:
if not visited[u]:
dfs(u)
dfs(arbitrary root)
Here, the variable represents the graph as an adjacency list, where is the list of vertices adjacent to the vertex in arbitrary order.
For example, when , it is possible to generate , by providing the graph as follows.
Here, the numbers written on vertices represent the order they are visited in the DFS. (The DFS starts at the vertex labeled .) The orange arrows show the transitions in the DFS, and the numbers next to them represent the order the edges are traversed.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
2 2
1
The only possible result is . Note that may have multi-edges.
3 4
9
10 20
186225754
100000 1000000
191021899