시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB444100.000%

문제

You have a DAG (Directed Acyclic Graph) with $n$ nodes and $m$ edges. The graph has exactly one node $x$ that has no outgoing edges. The $i$-th node has an integer value $a_i$ in it.

Every second, the following happens:

  • For each node $i$, let $b_i=a_i$.
  • For each node $i$, let $a_i=0$.
  • For each node $i$, and each node $j$ such that there is an edge from $i$ to $j$, the value $b_i$ is added to $a_j$.
  • The value $\left\lfloor \frac{b_x}{2} \right\rfloor$ is added to $a_x$.

Find the first moment of time when all $a_i$ become $0$. Since the answer can be very large, output it modulo $998\,244\,353$.

입력

The first line contains two integers $n$ and $m$ ($1\leq n\leq 10^4$; $1 \leq m \leq 10^5$): the number of vertices and edges in the graph.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 10^9$): the values in the vertices.

Each of the following $m$ lines contains two integers $u$ and $v$ ($1 \leq u, v \leq n$) which represent a directed edge from $u$ to $v$.

It is guaranteed that the graph is a DAG with no multi-edges, and there is exactly one node that has no outgoing edges.

출력

Print a line with a single integer: the first moment of time when all $a_i$ become $0$, modulo $998\,244\,353$.

예제 입력 1

3 2
1 1 1
1 2
2 3

예제 출력 1

3

예제 입력 2

6 8
1 1 4 5 1 4
1 4
1 5
2 3
2 5
3 4
4 5
4 6
5 6

예제 출력 2

8

예제 입력 3

5 6
7 2 3 6 6
1 2
1 4
2 3
3 4
3 5
4 5

예제 출력 3

9

노트

Hi, so to me seems like a notorious coincidence. (Codeforces 1704E)