Min-First SearchAI (CI翻译)
Problem Statement
For a tree $T$ with $N$ vertices called vertex $1$, vertex $2$, $\ldots$, vertex $N$, let $f(T)$ be the permutation $P$ of $(1,2,\ldots,N)$ obtained by the following procedure.
- Initially, let the sequence
$P$be the empty sequence$()$, and let the set$S$be$\lbrace1\rbrace$. - Repeat the following
$N$times. - Let
$x$be the minimum value of$S$. Remove$x$from$S$, and append$x$to the end of$P$.- Then, let
$v_1, v_2, \ldots, v_k$be the vertices adjacent to vertex$x$in$T$. For$i=1,2,\ldots,k$, if$v _ i$is not contained in$P$, add$v _ i$to$S$.
- Then, let
You are given a permutation $Q=(Q _ 1,Q _ 2,\ldots,Q _ N)$ of $(1,2,\ldots,N)$. Find the number, modulo $998244353$, of trees $T$ such that $f(T)=Q$. Here, two trees are distinguished when there exists a pair of vertices $(u,v)$ such that there is an edge between vertex $u$ and vertex $v$ in one tree and there is no edge in the other tree.
Constraints
$1\le N\le2\times10 ^ 5$$1\le Q _ i\le N\ (1\le i\le N)$$Q _ i\ne Q _ j\ (1\le i\lt j\le N)$$Q _ 1=1$- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
Q _ 1 Q _ 2 \ldots Q _ N
Output
Output the number, modulo $998244353$, of trees $T$ such that $f(T)=Q$.
{"titleZh":"最小值优先搜索","bodyZh":"## 题目描述\n\n对于一棵有 $N$ 个顶点(分别称为顶点 $1$、顶点 $2$、$\ldots$、顶点 $N$)的树 $T$,定义 $f(T)$ 为通过以下过程得到的 $(1,2,\\ldots,N)$ 的一个排列 $P$。\n\n- 初始时,令序列 $P$ 为空序列 $()$,集合 $S$ 为 $\\lbrace1\\rbrace$。\n- 重复以下操作 $N$ 次。\n- 取 $S$ 中的最小值 $x$。将 $x$ 从 $S$ 中删除,并将 $x$ 添加到 $P$ 的末尾。\n - 接着,令 $v_1, v_2, \\ldots, v_k$ 为树 $T$ 中与顶点 $x$ 相邻的顶点。对于 $i=1,2,\\ldots,k$,如果 $v _ i$ 不在 $P$ 中,则将 $v _ i$ 添加到 $S$ 中。\n\n给定 $(1,2,\\ldots,N)$ 的一个排列 $Q=(Q _ 1,Q _ 2,\\ldots,Q _ N)$。求满足 $f(T)=Q$ 的树 $T$ 的数量,对 $998244353$ 取模。若存在一对顶点 $(u,v)$,使得一棵树中顶点 $u$ 与顶点 $v$ 之间有边,而另一棵树中没有边,则认为这两棵树不同。\n\n## 约束条件\n\n- $1\\le N\\le2\\times10 ^ 5$\n- $1\\le Q _ i\\le N\\ (1\\le i\\le N)$\n- $Q _ i\\ne Q _ j\\ (1\\le i\\lt j\\le N)$\n- $Q _ 1=1$\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入给出,格式如下:\n\n\n\n## 输出格式\n\n输出满足 \nN\nQ _ 1 Q _ 2 \\ldots Q _ N\n$f(T)=Q$ 的树 $T$ 的数量,对 $998244353$ 取模。"}AI (CI翻译)
样例
5
1 3 4 2 5
8
20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
868586527
30
1 16 23 14 18 10 12 21 27 30 17 28 4 9 20 13 22 11 19 3 25 26 6 7 2 8 5 24 15 29
910753763
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。