AT_abc478_f.Min-First Search
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For a tree T with N vertices called vertex 1, vertex 2, …, vertex N, let f(T) be the permutation P of (1,2,…,N) obtained by the following procedure.
- Initially, let the sequence P be the empty sequence (), and let the set S be {1}.
- 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 v1,v2,…,vk be the vertices adjacent to vertex x in T. For i=1,2,…,k, if vi is not contained in P, add vi to S.
You are given a permutation Q=(Q1,Q2,…,QN) of (1,2,…,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.
对于一棵包含 N 个顶点的树 T,其顶点分别记为顶点 1、顶点 2、…、顶点 N。定义 f(T) 为通过以下过程得到的 (1,2,…,N) 的一个排列 P:
- 初始时,令序列 P 为空序列 (),集合 S={1}。
- 重复以下操作 N 次:
- 令 x 为集合 S 中的最小值。将 x 从 S 中移除,并将其追加到序列 P 的末尾。
- 设 v1,v2,…,vk 为树 T 中与顶点 x 相邻的所有顶点。对每个 i=1,2,…,k,若 vi 不在 P 中,则将 vi 加入 S。
现给定 (1,2,…,N) 的一个排列 Q=(Q1,Q2,…,QN)。求满足 f(T)=Q 的树 T 的数量(对 998244353 取模)。此处,若存在一对顶点 (u,v),使得某棵树中包含边 (u,v) 而另一棵树中不包含该边,则认为这两棵树不同。
输入格式
The input is given from Standard Input in the following format:
N
Q1 Q2 … QN
输入从标准输入中按以下格式给出:
N
Q1 Q2 … QN
输出格式
Output the number, modulo 998244353, of trees T such that f(T)=Q.
输出满足 f(T)=Q 的树 T 的数量,结果对 998244353 取模。
输入输出样例
输入#1
5 1 3 4 2 5
输出#1
8
输入#2
20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
输出#2
868586527
输入#3
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
输出#3
910753763
说明/提示
Sample 1 Explanation:
For example, if T is the following tree, then f(T)=Q.

The procedure to find f(T) proceeds as shown in the following figure.

Including this tree, the following eight trees satisfy the condition.

Thus, output 8.
Sample 2 Explanation:
Output modulo 998244353 the number of trees satisfying the condition.
Constraints
- 1≤N≤2×105
- 1≤Qi≤N (1≤i≤N)
- Qi=Qj (1≤i<j≤N)
- Q1=1
- All input values are integers.
样例 1 解释:
例如,若 T 是如下所示的树,则 f(T)=Q。

求 f(T) 的过程如以下图示所示。

包含该树在内,共有如下八棵满足条件的树。

因此,输出 8。
样例 2 解释:
输出满足条件的树的数量对 998244353 取模的结果。
约束条件
- 1≤N≤2×105
- 1≤Qi≤N (1≤i≤N)
- Qi=Qj (1≤i<j≤N)
- Q1=1
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?