Confusion
Time limit5sMemory limit1024 MB
Count the simple cycles in a triangulated convex polygon with N vertices, given its N-3 non-crossing diagonals, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Graph, Dynamic programming, Tree
- Solved
- No attempts yet
Problem
Mr. Malnar decided to spend his summer traveling around the world by flying randomly. After some time, he found himself in an unknown country's capital, where the streets reminded him of a triangulation. More precisely, the city consists of interesting locations numbered from to , connected by streets. Locations are connected in that order to form a convex polygon with sides. The remaining streets connect locations so that no two streets cross, except possibly at their ends.
While walking the streets, Mr. Malnar returned to the location where he started without visiting any location more than once. He decided this is normal and defined the confusion of the city as the number of simple closed loops.
A simple closed walk is a sequence of locations such that is connected by a street to for every , and is connected by a street to . Two walks are equivalent if one can be obtained from the other by a cyclic rotation or by reversing it. For example, the walk is equivalent to the walk . A simple closed loop is a set of equivalent walks.
Mr. Malnar asks you to calculate the confusion of this city.
Input
The first line contains an integer (), the number of locations.
Each of the next lines contains two integers and (), the labels of the locations connected by the -th street.
Output
Print the confusion of the city modulo .