Beautiful Graph
Time limit2sMemory limit512 MB
Over all complete graphs on N vertices whose edges cost 1 or 2, sum the number of minimum spanning trees that are paths (every degree at most 2).
- Level
Hard8 of 10
- Topics
- Graph, Minimum spanning tree, Combinatorics, Dynamic programming
- Solved
- No attempts yet
Problem
You are given an integer .
A complete graph has exactly one undirected edge between every pair of distinct vertices.
A graph is beautiful when it meets both conditions below.
- It is a complete graph on vertices.
- Every edge has cost or cost .
So there are beautiful graphs.
A minimum spanning tree (MST) of a beautiful graph is a subgraph that meets these conditions.
- It contains all vertices of .
- It is connected, so a path joins every pair of its vertices.
- The sum of the costs of its edges is minimum.
One beautiful graph can have several MSTs. Their costs are all equal.
An MST is a line when every vertex in it has degree at most .
Let be the number of MSTs of a beautiful graph that are lines.
Print the sum of over all beautiful graphs on vertices, modulo 1,000,000,007.
Input
The first line contains . ()
Output
Print the answer on the first line.