#P10324. 洞察(Insight)

    ID: 11498 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学洛谷原创O2优化组合数学生成函数拉格朗日反演洛谷比赛

洞察(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 GG, there are nn black vertices, nn white vertices, and 11 red vertex.
All vertices are labeled. The graph has 2n2n 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 type\text{type} equal to 00 or 11, compute how many graphs GG satisfy the conditions under different requirements:

  • type=0\text{type}=0: No additional requirements.
  • type=1\text{type}=1: 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 998244353998244353.

Input Format

One line with two integers nn and type\text{type}.

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 11 Explanation]
Here type=1\text{type}=1. All 55 valid graphs are:

  1. RWBR-W'-B
  2. RWBR-W-B'
  3. RBWR-B'-W
  4. RBWR-B-W'
  5. BRWB'-R-W'

Since n=1n=1, we can use only BB and WW to distinguish the white vertex and the black vertex. RR denotes the red vertex. The dash in the middle denotes an edge. BB' and WW' denote the marked black vertex and the marked white vertex, respectively.

Note that in the 5th graph, the single BB and the single WW are maximal connected subgraphs that do not contain RR, so each must have a mark at this only possible position.

[Sample 2,32,3 Explanation]

See the attached images, which show all 4545 possible graphs GG when type=0\text{type}=0.

For type=1\text{type}=1, you only need to add marks on top of each graph, and you can count that the answer is 149149.

[Sample 4,54,5 Explanation]

Before taking modulo, the answers are 116758263583336861101116758263583336861101 and $4159784334433940020473603987503242886367209494283213841$, respectively.

[Constraints]

This problem uses bundled testdata.

Subtask 1 (8 pts): n4n \le 4;
Subtask 2 (10 pts): n103n \le 10^3, type=0\text{type}=0;
Subtask 3 (11 pts): type=0\text{type}=0;
Subtask 4 (13 pts): n100n \le 100, type=1\text{type}=1;
Subtask 5 (14 pts): n103n \le 10^3, type=1\text{type}=1;
Subtask 6 (21 pts): n105n \le 10^5, type=1\text{type}=1;
Subtask 7 (23 pts): type=1\text{type}=1.

For all testdata, 1n1071 \le n \le 10^7, type{0,1}\text{type} \in \{0,1\}.

[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