IRCTC

4.2

11 votes
Approved, Basic Programming, Graphs, Medium, Open, Shortest Path Algorithm
Problem

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

Sample Input
2
6 6
1 2 2
2 5 5
2 3 4
1 4 1
4 3 3
3 5 1
1 3 6
10 10
1 5 78
1 8 221
2 7 92
2 8 159
3 5 55
3 6 179
3 10 237
4 8 205
5 6 191
8 10 157
6 3 2
Sample Output
No Train Found.
692
6 3 5 1 8 2 
Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?