#ABC281G. [ABC281G] Farthest City

    ID: 1552 Type: RemoteJudge 4000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>动态规划,dp组合数学排列组合

[ABC281G] Farthest City

Score : 600600 points

Problem Statement

You are given positive integers NN and MM. Find the number, modulo MM, of simple connected undirected graphs with NN vertices numbered 1,,N1, \dots, N that satisfy the following condition.

  • For every u=2,,N1u = 2, \dots, N-1, the shortest distance from vertex 11 to vertex uu is strictly smaller than the shortest distance from vertex 11 to vertex NN.

Here, the shortest distance from vertex uu to vertex vv is the minimum number of edges in a simple path connecting vertices uu and vv. Two graphs are considered different if and only if there are two vertices uu and vv that are connected by an edge in exactly one of those graphs.

Constraints

  • 3N5003 \leq N \leq 500
  • 108M10910^8 \leq M \leq 10^9
  • NN and MM are integers.

Input

The input is given from Standard Input in the following format:

NN MM

Output

Print the answer.

4 1000000000
8

The following eight graphs satisfy the condition.

example_00

3 100000000
1
500 987654321
610860515

Be sure to find the number modulo MM.