AtCoder Regular Contest 140
D
One to One
AtCoder
⌀ 2443
原题
← CE →
翻译中…

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.

翻译中…

样例

Input #1
3
-1 1 3
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$.
Input #2
1
1
Output #2
1
Input #3
8
-1 3 -1 -1 8 -1 -1 -1
Output #3
433760
题目信息
题号
arc140_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。