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$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.