201403: [AtCoder]ARC140 D - One to One

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $700$ points

Problem Statement

For an integer sequence $X=(X_1,X_2,\dots,X_N)$ of length $N$ whose elements are all between $1$ and $N$ (inclusive), consider the question below, and let $f(X)$ be the answer.

There is an undirected graph $G$ with $N$ vertices (and possibly multi-edges and self-loops). $G$ has $N$ edges, the $i$-th of which connects Vertex $i$ and Vertex $X_i$. Find the number of connected components in $G$.

You are given an integer sequence $A=(A_1,A_2,\dots,A_N)$ of length $N$, where each $A_i$ is an integer between $1$ and $N$ (inclusive) or $-1$.

Consider an integer sequence $X=(X_1,X_2,\dots,X_N)$ of length $N$ whose elements are all between $1$ and $N$ such that $A_i \neq -1 \Rightarrow A_i = X_i$. Find the sum of $f(X)$ over all such $X$, modulo $998244353$.

Constraints

  • $1 \le N \le 2000$
  • $A_i$ is between $1$ and $N$ (inclusive) or $-1$.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\dots$ $A_N$

Output

Prin the answer.


Sample Input 1

3
-1 1 3

Sample Output 1

5

There are three sequences $X$ satisfying the requirement, as follows.

  • $X=(1,1,3)$, for which the answer to the question is $2$.
  • $X=(2,1,3)$, for which the answer to the question is $2$.
  • $X=(3,1,3)$, for which the answer to the question is $1$.

Thus, the answer is $2+2+1=5$.


Sample Input 2

1
1

Sample Output 2

1

Sample Input 3

8
-1 3 -1 -1 8 -1 -1 -1

Sample Output 3

433760

Input

题意翻译

你有一个长度为 $n$ 的序列 $a_1,a_2,\dots,a_n$,其中每个元素都是 $[1,n]$ 中的整数。 初始时有编号为 $1 \sim n$ 的 $n$ 个节点,对于每个 $1\leq i \leq n$,从 $i$ 向 $a_i$ 连一条无向边。$a_i=-1$ 表示 $a_i$ 还没有确定。你需要对所有可能的 $a$ 序列求出图中连通块数量的和对 $998244353$ 取模的结果。

加入题单

上一题 下一题 算法标签: