Logo
(追記) (追記ここまで)

32085번 - Count BFS Graph 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB69484267.742%

문제

You are currently researching a graph traversal algorithm called the Breadth First Search (BFS). Suppose you have an input graph of $N$ nodes (numbered from 1ドル$ to $N$). The graph is represented by an adjacency matrix $M,ドル for which node $u$ can traverse to node $v$ if $M_{u,v}$ is 1ドル,ドル otherwise it is 0ドル$. Your algorithm will output the order the nodes are visited in the BFS. The pseudocode of the algorithm is presented as follows.

BFS(M[1..N][1..N]):
 let A be an empty array
 let Q be an empty queue
 append 1 to A
 push 1 to Q
 while Q is not empty:
 pop the front element of Q into u
 for v = 1 to N:
 if M[u][v] == 1 and v is not in A:
 append v to A
 push v to Q
 return A

During your research, you are interested in the following problem. Given an array $A$ such that $A$ is a permutation of 1ドル$ to $N$ and $A_1 = 1$. How many simple undirected graph with $N$ nodes and adjacency matrix $M$ such that $\text{BFS}(M) = A$? Since the answer can be very large, calculate the answer modulo 998ドル,円 244,円 353$.

A simple graph has no self-loop ($M_{i,i} = 0$ for 1ドル ≤ i ≤ N$) and there is at most one edge that connects a pair of nodes. In an undirected graph, if node $u$ is adjacent to node $v,ドル then node $v$ is also adjacent to node $u$; formally, $M_{u,v} = M_{v,u}$ for 1ドル ≤ u < v ≤ N$.

Two graphs are considered different if there is an edge that exists in one graph but not the other. In other words, two graphs are considered different if their adjacency matrices are different.

입력

The first line consists of an integer $N$ (2ドル ≤ N ≤ 5000$).

The second line consists of $N$ integers $A_i$. The array $A$ is a permutation of 1ドル$ to $N$ and $A_1 = 1$.

출력

Output an integer representing the number of simple undirected graphs with $N$ nodes and adjacency matrix $M$ such that $\text{BFS}(M) = A$. Since the answer can be very large, output the answer modulo 998ドル,円 244,円 353$.

제한

예제 입력 1

3
1 2 3

예제 출력 1

3

The following illustration shows all graphs that satisfy the requirements.

예제 입력 2

3
1 3 2

예제 출력 2

1

The only graph that satisfies the requirements is a graph with two edges: one that connects nodes 1ドル$ and 3ドル,ドル and another one that connects nodes 3ドル$ and 2ドル$.

예제 입력 3

5
1 3 2 4 5

예제 출력 3

17

예제 입력 4

11
1 2 3 4 5 6 7 8 9 10 11

예제 출력 4

379394847

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > The 2023 ICPC Asia Jakarta Regional Contest J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /