#P4779. 【模板】单源最短路径(标准版)

【模板】单源最短路径(标准版)

Description

Given a directed graph with nn nodes and mm directed edges with non-negative weights, please compute the distance from ss to every node.

The testdata guarantees that you can reach every node starting from ss.

Input Format

The first line contains three positive integers n,m,sn, m, s. Starting from the second line, there are mm lines. Each line contains three non-negative integers ui,vi,wiu_i, v_i, w_i, meaning there is a directed edge from uiu_i to viv_i with weight wiw_i.

Output Format

Output one line with nn space-separated non-negative integers, representing the distance from ss to each node.

4 6 1
1 2 2
2 3 2
2 4 1
1 3 5
3 4 3
1 4 4
0 2 4 3

Hint

For the sample explanation, please refer to Template Problem with Random Data.

Constraints:

1n1051 \leq n \leq 10^5;

1m2×1051 \leq m \leq 2\times 10^5;

s=1s = 1;

1ui,vin1 \leq u_i, v_i\leq n;

0wi1090 \leq w_i \leq 10 ^ 9,

0wi1090 \leq \sum w_i \leq 10 ^ 9

The testdata of this problem may continue to be updated, but it will not be rejudged. Please be informed.

2018.09.04 Data update from @zzq.

Translated by ChatGPT 5