IRCTC
Practice
4.2 (11 votes)
Approved
Basic programming
Graphs
Medium
Open
Shortest path algorithm
Problem
50% Success 1082 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Good news , You have a chance to work in IRCTC as a software developer . Applications are required with a program for railway sites . sid of a station is a something which uniquely defines it . Given N station's sid from 1 to N and distance between any two stations , if any person wants to go from station having sid A to another station C via station B as early as possible , where time is directly proportional to distance . What you have to do is to print the total distance and path to be covered by train if it exists , otherwise print "No Train Found.". If a railway line connects station A to B with distance d than it means it will also connects station B to station A with same distance d .

Input
First line of the input contains the number of test cases T. It is followed by T tests cases. Each test case's first line contains two integers N and k , where N is the number of stations having sid from 1 to N and k is the number of railway lines which connects stations. Following k lines each contain three numbers a , b and d which represents station having sid a connects station b and distance between them is d . After that a line follows with number A , B , C , where A represents sid of the source station , C the destination station and B is the station via which person wants to go.

Output
For each test case , If there exists no paths as described in problem print "No Train Found." otherwise in first line print the total distance and in second line path to be covered .

Constraints
1 <= t <= 100
1 <= k <= 100000
3 <= N <= 100000
1 <= A,B,C <= N
1 <= d <= 10000000

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
AlgorithmsBinary SearchFloyd Warshall AlgorithmGraphsMediumShortest Path Algorithm
Points:30
52 votes
Tags:
AlgorithmsC++GraphsShortest Path Algorithm
Points:20
11 votes
Tags:
Basic ProgrammingEasyOpenApprovedHash table