QOJ.ac

QOJ

Time Limit: 3.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#1446. 最短路 2

統計

给定一张 $n$ 个点 $m$ 条边的带权有向图,权值可能为负,求起点 $s$ 到所有点的最短路。

输入格式

第一行三个由空格隔开的整数 $ n $、$ m $、$ s $。

之后的 $ m $ 行,每行三个正整数 $ s_i $、$ t_i $、$w_i$ ($1 \le s_i, t_i \le n$, $-10^9 \leq w_i \leq 10 ^ 9$) ,表示一条从 $ s_i $ 到 $ t_i $ 长度为 $ w_i $ 的有向边。图中可能存在重边或自环。

输出格式

输出一行,包含 $n$ 个整数 $d_1, d_2, \ldots, d_n$。其中 $d_i$ 表示从 $s$ 到 $i$ 的最短路长度。如果不存在对应的道路,输出 N/A。如果对应的最短路为负无穷,输出 -inf

样例数据

样例 1 输入

4 5 1
1 2 1000
2 3 10000
3 1 1
3 4 100000
3 4 1000000

样例 1 输出

0 1000 11000 111000

样例 2 输入

4 4 2
1 2 1
2 3 1000000000
3 4 -1
4 3 -1

样例 2 输出

N/A 0 -inf -inf

子任务

对于所有数据,$1 \le n \le 5\,000$,$0 \le m \le 3 \cdot 10^5$。

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.