CF1704E.Count Seconds

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Cirno has a DAG (Directed Acyclic Graph) with nn nodes and mm edges. The graph has exactly one node that has no out edges. The ii-th node has an integer aia_i on it.

Every second the following happens:

  • Let SS be the set of nodes xx that have ax>0a_x \gt 0.
  • For all x∈Sx \in S, 11 is subtracted from axa_x, and then for each node yy, such that there is an edge from xx to yy, 11 is added to aya_y.

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

Cirno 有一个包含 nn 个节点和 mm 条边的有向无环图(DAG)。该图中恰好存在一个没有出边的节点。第 ii 个节点上有一个整数 aia_i。

每一秒内,以下操作发生:

  • 设 SS 为所有满足 ax>0a_x > 0 的节点 xx 构成的集合;
  • 对每个 x∈Sx \in S,将 axa_x 减去 11;然后对每个从 xx 到 yy 存在一条有向边的节点 yy,将 aya_y 加上 11。

求所有 aia_i 首次全部变为 00 的时刻。由于答案可能非常大,请将结果对 998 244 353998\,244\,353 取模后输出。

输入格式

The first line contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases. Description of test cases follows.

The first line of each test case contains two integers n,mn, m (1≤n,m≤10001 \leq n, m \leq 1000) — the number of vertices and edges in the graph.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \leq a_i \leq 10^9) — the integer on vertices.

Each line of the following mm lines contains two integers x,yx, y (1≤x,y≤n1 \leq x, y \leq n), represent a directed edge from xx to yy. It is guaranteed that the graph is a DAG with no multi-edges, and there is exactly one node that has no out edges.

It is guaranteed that both sum of nn and sum of mm over all test cases are less than or equal to 10 00010\,000.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000)—— 测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 n,mn, m(1≤n,m≤10001 \leq n, m \leq 1000)—— 图中顶点和边的数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \leq a_i \leq 10^9)—— 各顶点上的整数值。

接下来的 mm 行,每行包含两个整数 x,yx, y(1≤x,y≤n1 \leq x, y \leq n),表示一条从 xx 指向 yy 的有向边。保证该图是一个无重边的有向无环图(DAG),且恰好存在一个出度为 0 的节点。

保证所有测试用例中 nn 的总和与 mm 的总和均不超过 10 00010\,000。

输出格式

For each test case, print an integer in a separate line — the first moment of time when all aia_i become 00, modulo 998 244 353998\,244\,353.

对于每个测试用例,在单独一行中输出一个整数——所有 aia_i 首次全部变为 00 的时刻(对 998 244 353998\,244\,353 取模)。

输入输出样例

  • 输入#1

    5
    3 2
    1 1 1
    1 2
    2 3
    5 5
    1 0 0 0 0
    1 2
    2 3
    3 4
    4 5
    1 5
    10 11
    998244353 0 0 0 998244353 0 0 0 0 0
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    7 8
    8 9
    9 10
    1 3
    7 9
    5 6
    1293 1145 9961 9961 1919
    1 2
    2 3
    3 4
    5 4
    1 4
    2 4
    6 9
    10 10 10 10 10 10
    1 2
    1 3
    2 3
    4 3
    6 3
    3 5
    6 5
    6 1
    6 2

    输出#1

    3
    5
    4
    28010
    110

说明/提示

In the first test case:

  • At time 00, the values of the nodes are [1,1,1][1, 1, 1].
  • At time 11, the values of the nodes are [0,1,1][0, 1, 1].
  • At time 22, the values of the nodes are [0,0,1][0, 0, 1].
  • At time 33, the values of the nodes are [0,0,0][0, 0, 0].

So the answer is 33.

In the second test case:* At time 00, the values of the nodes are [1,0,0,0,0][1, 0, 0, 0, 0].

  • At time 11, the values of the nodes are [0,1,0,0,1][0, 1, 0, 0, 1].
  • At time 22, the values of the nodes are [0,0,1,0,0][0, 0, 1, 0, 0].
  • At time 33, the values of the nodes are [0,0,0,1,0][0, 0, 0, 1, 0].
  • At time 44, the values of the nodes are [0,0,0,0,1][0, 0, 0, 0, 1].
  • At time 55, the values of the nodes are [0,0,0,0,0][0, 0, 0, 0, 0].

So the answer is 55.

In the third test case:

The first moment of time when all aia_i become 00 is 6⋅998244353+46\cdot 998244353 + 4.

在第一个测试用例中:

  • 在时刻 00,各节点的值为 [1,1,1][1, 1, 1]。
  • 在时刻 11,各节点的值为 [0,1,1][0, 1, 1]。
  • 在时刻 22,各节点的值为 [0,0,1][0, 0, 1]。
  • 在时刻 33,各节点的值为 [0,0,0][0, 0, 0]。

因此答案为 33。

在第二个测试用例中:

  • 在时刻 00,各节点的值为 [1,0,0,0,0][1, 0, 0, 0, 0]。
  • 在时刻 11,各节点的值为 [0,1,0,0,1][0, 1, 0, 0, 1]。
  • 在时刻 22,各节点的值为 [0,0,1,0,0][0, 0, 1, 0, 0]。
  • 在时刻 33,各节点的值为 [0,0,0,1,0][0, 0, 0, 1, 0]。
  • 在时刻 44,各节点的值为 [0,0,0,0,1][0, 0, 0, 0, 1]。
  • 在时刻 55,各节点的值为 [0,0,0,0,0][0, 0, 0, 0, 0]。

因此答案为 55。

在第三个测试用例中:

所有 aia_i 首次全部变为 00 的时刻为 6⋅998244353+46\cdot 998244353 + 4。

输入解题思路,AI测评打分。不知道怎么写?

首页