AT_ndpc2026_b.DAG

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a simple directed graph with NN vertices and MM edges. The vertices are numbered from 11 to NN. The ii-th edge goes from vertex uiu_i to vertex viv_i.
This graph has no cycles.

Find the number of paths from vertex 11 to vertex NN, modulo 998244353998244353.

You are given TT test cases. Solve each of them.

给你一个包含 NN 个顶点和 MM 条边的有向无环图(DAG)。顶点编号为 11 到 NN。第 ii 条边从顶点 uiu_i 指向顶点 viv_i。
该图不含环。

求从顶点 11 到顶点 NN 的路径数量,结果对 998244353998244353 取模。

你将得到 TT 组测试数据。请分别求解每组数据。

输入格式

The input is given from standard input in the following format:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN MM
u1u_1 v1v_1
u2u_2 v2v_2
⋮\vdots
uMu_M vMv_M

输入从标准输入中按以下格式给出:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例按以下格式给出:

NN MM
u1u_1 v1v_1
u2u_2 v2v_2
⋮\vdots
uMu_M vMv_M

输出格式

Print TT lines. For the ii-th line, output the answer for the ii-th test case.
For each test case, output the number of paths from vertex 11 to vertex NN, modulo 998244353998244353.

输出 TT 行。第 ii 行输出第 ii 个测试用例的答案。
对于每个测试用例,输出从顶点 11 到顶点 NN 的路径数量,对 998244353998244353 取模。

输入输出样例

  • 输入#1

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

    输出#1

    2
    0
    24

说明/提示

Sample 1 Explanation:
For the first test case, there are 22 paths from vertex 11 to vertex 44:

  • vertex 11 →\to vertex 22 →\to vertex 33 →\to vertex 44
  • vertex 11 →\to vertex 22 →\to vertex 44

Constraints

  • 1≤T≤1051 \leq T \leq 10^5
  • 2≤N≤2×1052 \leq N \leq 2 \times 10^5
  • 0≤M≤min⁡(N(N−1)2,2×105)0 \leq M \leq \min\left(\frac{N(N-1)}{2}, 2 \times 10^5\right)
  • 1≤ui≤N1 \leq u_i \leq N
  • 1≤vi≤N1 \leq v_i \leq N
  • If i≠ji \neq j, then (ui,vi)≠(uj,vj)(u_i, v_i) \neq (u_j, v_j)
  • The given graph is a simple directed graph with no cycles
  • The sum of NN over all test cases is at most 2×1052 \times 10^5
  • The sum of MM over all test cases is at most 2×1052 \times 10^5
  • All input values are integers

样例 1 解释:
对于第一个测试用例,从顶点 11 到顶点 44 共有 22 条路径:

  • 顶点 11 →\to 顶点 22 →\to 顶点 33 →\to 顶点 44
  • 顶点 11 →\to 顶点 22 →\to 顶点 44

约束条件

  • 1≤T≤1051 \leq T \leq 10^5
  • 2≤N≤2×1052 \leq N \leq 2 \times 10^5
  • 0≤M≤min⁡(N(N−1)2,2×105)0 \leq M \leq \min\left(\frac{N(N-1)}{2}, 2 \times 10^5\right)
  • 1≤ui≤N1 \leq u_i \leq N
  • 1≤vi≤N1 \leq v_i \leq N
  • 若 i≠ji \neq j,则 (ui,vi)≠(uj,vj)(u_i, v_i) \neq (u_j, v_j)
  • 给定图是一个无环的简单有向图
  • 所有测试用例中 NN 的总和不超过 2×1052 \times 10^5
  • 所有测试用例中 MM 的总和不超过 2×1052 \times 10^5
  • 所有输入值均为整数

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

首页