AT_ndpc2026_b.DAG
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a simple directed graph with N vertices and M edges. The vertices are numbered from 1 to N. The i-th edge goes from vertex ui to vertex vi.
This graph has no cycles.
Find the number of paths from vertex 1 to vertex N, modulo 998244353.
You are given T test cases. Solve each of them.
给你一个包含 N 个顶点和 M 条边的有向无环图(DAG)。顶点编号为 1 到 N。第 i 条边从顶点 ui 指向顶点 vi。
该图不含环。
求从顶点 1 到顶点 N 的路径数量,结果对 998244353 取模。
你将得到 T 组测试数据。请分别求解每组数据。
输入格式
The input is given from standard input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N M
u1 v1
u2 v2
⋮
uM vM
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个测试用例按以下格式给出:
N M
u1 v1
u2 v2
⋮
uM vM
输出格式
Print T lines. For the i-th line, output the answer for the i-th test case.
For each test case, output the number of paths from vertex 1 to vertex N, modulo 998244353.
输出 T 行。第 i 行输出第 i 个测试用例的答案。
对于每个测试用例,输出从顶点 1 到顶点 N 的路径数量,对 998244353 取模。
输入输出样例
输入#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 2 paths from vertex 1 to vertex 4:
- vertex 1 → vertex 2 → vertex 3 → vertex 4
- vertex 1 → vertex 2 → vertex 4
Constraints
- 1≤T≤105
- 2≤N≤2×105
- 0≤M≤min(2N(N−1),2×105)
- 1≤ui≤N
- 1≤vi≤N
- If i=j, then (ui,vi)=(uj,vj)
- The given graph is a simple directed graph with no cycles
- The sum of N over all test cases is at most 2×105
- The sum of M over all test cases is at most 2×105
- All input values are integers
样例 1 解释:
对于第一个测试用例,从顶点 1 到顶点 4 共有 2 条路径:
- 顶点 1 → 顶点 2 → 顶点 3 → 顶点 4
- 顶点 1 → 顶点 2 → 顶点 4
约束条件
- 1≤T≤105
- 2≤N≤2×105
- 0≤M≤min(2N(N−1),2×105)
- 1≤ui≤N
- 1≤vi≤N
- 若 i=j,则 (ui,vi)=(uj,vj)
- 给定图是一个无环的简单有向图
- 所有测试用例中 N 的总和不超过 2×105
- 所有测试用例中 M 的总和不超过 2×105
- 所有输入值均为整数
输入解题思路,AI测评打分。不知道怎么写?