IITKESO207SPA3F2 - Simple Dijkstras algorithm again

no tags 

Problem statement

 

Implement the Dijkstra's algorithm for the simple case of a directed  graph. You will be given two nodes, a source and a destination. You have to compute the shortest path between these two nodes.

 

Input format

 

The input consists of multiple lines. The first line holds three numbers n s d denoting the number of nodes, the source node, and the destination node. Notice that nodes are labelled from 0 to n-1.

 

The next lines contain the edges in the format i j w which denotes the presence of an edge between nodes i and j of weight w.

 

Output format

 

Your output must be in multiple lines. The first line must be the value (as an integer) of the shortest path length. The next lines must be the nodes on the path in order. If there are multiple paths with the same weight, choose the path that has minimum number of edges

 

Sample input

 

 5 0 4

0 1 2

0 2 8

0 3 5

1 2 1

2 4 3

3 4 4

 

Sample output

6

0 1 2 4



Added by:Programming Club, IITK
Date:2017-07-06
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:ESO207, IIT Kanpur Summer Semester 2017