Shortest Path Problem

3.2

4 votes
Very-Easy
Problem

You are given 2 integers (N,M), N is the number of vertices, M is the number of edges. You'll also be given ai , bi, wi where ai and bi represents an edge from a vertex ai to a vertex bi and wi respresents the weight of that edge.

Task is to find the shortest path from source vertex (vertex number 1) to all other vertices (vi) where (2iN).

Input:

First line contains two space separated integers, (N,M) Then M lines follow, each line has 3 space separated integers ai , bi, wi.

Output:
Print the shortest distances from the source vertex (vertex number 1) to all other vertices (vi) where (2iN). Print "109" in case the vertex "vi" can't be reached form the source vertex.
Leave a space between any 2 printed numbers.

Constraints:
(1N104)
(1M106)
(1ai,biN)
(1wi1000)

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?