#abc281g. G - Farthest City

G - Farthest City

Score : 600600 points

问题描述

给定正整数 NNMM

求满足以下条件的简单连通无向图的数量,对模 MM

  • 对于所有 u=2,,N1u = 2, \dots, N-1,从顶点 11 到顶点 uu 的最短距离严格小于从顶点 11 到顶点 NN 的最短距离。

这里,从顶点 uu 到顶点 vv 的最短距离是在一条简单路径中连接顶点 uuvv 的最少边数。
两个图仅当存在两个顶点 uuvv 在其中一个图中通过一条边相连而在另一个图中没有相连时,被认为是不同的。

以上为通义千问 qwen-max 翻译,仅供参考。

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.

Sample Input 1

4 1000000000

Sample Output 1

8

The following eight graphs satisfy the condition.

example_00

Sample Input 2

3 100000000

Sample Output 2

1

Sample Input 3

500 987654321

Sample Output 3

610860515

Be sure to find the number modulo MM.

update @ 2024/3/10 11:49:01