1417: 最短路(Spfa)

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:38 Solved:4

Description

给定 MM 条边, NN 个点的带权无向图。求 11到 NN 的最短路。

Input

第一行:N,M(N<=100000,M<=500000);

接下来M行3个正整数:ai,bi,ci表示ai,bi之间有一条长度为ci的路,ci<=1000。

Output

一个整数,表示 1 到 N 的最短距离。

Sample Input Copy

4 4
1 2 1
2 3 1
3 4 1
2 4 1

Sample Output Copy

2

HINT

【样例解释】

注意图中可能有重边和自环,数据保证 1 到 N 有路径相连。

Source/Category