## Single Source Shortest Path

View as PDF

Points: 7
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Solve the Single Source Shortest Path problem.

#### Input Specification

Line : (vertices), (bidirectional edges)

Lines to : , a bidirectional edge from to with weight . Multiple edges between the same pair of vertices may occur in the input.

#### Output Specification

Lines to : line has the length of the shortest path from vertex to vertex . If no path exists, output -1.

#### Sample Input

4 3
1 2 2
1 3 5
2 3 2

#### Sample Output

0
2
4
-1

• commented on April 14, 2020, 9:01 p.m.

Like how are the nodes linked?

• commented on April 15, 2020, 2:49 a.m.

• commented on April 15, 2020, 7:27 p.m.

thank you!

• commented on Jan. 24, 2018, 12:14 p.m.

Can someone please tell me what is wrong with my c++ code? I just translated my Python Code, which passed with AC, into a c++ one, but it gets the majority of the cases wrong. Thanks in advance.

• commented on Jan. 24, 2018, 1:08 p.m.

• commented on Jan. 24, 2018, 5:14 p.m.

I am actually dumb, I forgot that "Multiple edges between the same pair of vertices may occur in the input." Thanks for the reply.

• commented on Feb. 25, 2017, 11:50 a.m. edited

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Feb. 25, 2017, 11:58 a.m.

a bidirectional edge from to with weight .

So, undirected.

• commented on Feb. 25, 2017, 12:05 p.m.

thanks