Labeled Connected Graphs
Time limit2sMemory limit512 MB
Sum the distance between vertices 1 and 2 over every labeled connected graph on n vertices, modulo a prime m.
- Level
Hard9 of 10
- Topics
- Combinatorics, Dynamic programming, Math, Graph
- Solved
- No attempts yet
Problem
You are given an integer and a prime modulo .
Calculate the sum of distances between the first and the second vertices over all distinct labeled connected graphs with vertices.
Output any integer congruent to the actual sum modulo . Formally, if the actual sum is , output any integer such that and is divisible by .
Input
The only line contains two integers and (, , is prime), the number of vertices in the graphs and the modulo.
Output
Print a single integer: the answer to the problem.
Hint
If you manage to get WA in this problem and we reasonably believe that you did not intentionally try to do so, we might give you a cookie somehow.