| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 2048 MB | 4 | 4 | 4 | 100.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:
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$.
3 2 1 1 1 1 2 2 3
3
6 8 1 1 4 5 1 4 1 4 1 5 2 3 2 5 3 4 4 5 4 6 5 6
8
5 6 7 2 3 6 6 1 2 1 4 2 3 3 4 3 5 4 5
9
Hi, so to me seems like a notorious coincidence. (Codeforces 1704E)