#P10324. 洞察(Insight)
洞察(Insight)
Background
A new perspective that sees everything without bias — Insight.
"Light of Insight" Kai Yas De Brad is a subtraction thief, and also a chaos knight carrying a dark fate.
Inside Kai’s right hand lies the Sword of Chaos. To make it release enough power without losing control, a specific internal structure must be satisfied. She wants to know how many structures meet the requirements. To make the computation easier, she transforms the problem into the following form.
Problem Description
Update during the contest: A typo in the statement has been fixed to: the colors of every pair of adjacent vertices are all different.
In an undirected connected graph , there are black vertices, white vertices, and red vertex.
All vertices are labeled. The graph has edges, and the colors of every pair of adjacent vertices (i.e., every pair of vertices directly connected by an edge) are also all different.
For equal to or , compute how many graphs satisfy the conditions under different requirements:
- : No additional requirements.
- : For every maximal connected subgraph that does not contain the red vertex, you must place a special mark on exactly one vertex (each mark is also distinct).
Output the answer modulo .
Input Format
One line with two integers and .
Output Format
One line with one integer, the answer.
1 1
5
2 0
45
2 1
149
10 0
36011666
20 1
593465999
106 1
516553582
Hint
[Sample Explanation]
Here . All valid graphs are:
Since , we can use only and to distinguish the white vertex and the black vertex. denotes the red vertex. The dash in the middle denotes an edge. and denote the marked black vertex and the marked white vertex, respectively.
Note that in the 5th graph, the single and the single are maximal connected subgraphs that do not contain , so each must have a mark at this only possible position.
[Sample Explanation]
See the attached images, which show all possible graphs when .
For , you only need to add marks on top of each graph, and you can count that the answer is .
[Sample Explanation]
Before taking modulo, the answers are and $4159784334433940020473603987503242886367209494283213841$, respectively.
[Constraints]
This problem uses bundled testdata.
Subtask 1 (8 pts): ;
Subtask 2 (10 pts): , ;
Subtask 3 (11 pts): ;
Subtask 4 (13 pts): , ;
Subtask 5 (14 pts): , ;
Subtask 6 (21 pts): , ;
Subtask 7 (23 pts): .
For all testdata, , .
[Hint]
For problems like this, you might want to look for an answer on OEIS. But I want to remind you that directly searching the sequence of answers will not find anything. However, for small constraints, you can still precompute the answer sequence in advance.
Translated by ChatGPT 5