I have a graph which is a sequence of edges with associated distance (travel time), as well as a start and destination node with an associated maximum allowed travel time. All edges can be traveled both ways.
I want to determine the single shortest path between the start and destination, and print the route if the distance of the path is equal or less than the maximum allowed travel time.
Input
Input is read from standard input and has the following characteristics:
Output
Output is written to standard output and must have the following characteristics:
Errors
You should detect the following errors:
Code - Type
E1 - Input syntax error
E2 - Logical input error
E3 - Failed to find a suitable route
Logical input errors are: duplicate definitions of edges, specifying either a start or destination node (second line) that is not actually defined in the graph (first line), disconnected graphs, or more than one shortest path found.
Output Representation
If there were no errors and the shortest route is found, the nodes should be printed in traveling order, including the start and destination, separated by ASCII arrow '->' (two characters).
Sample Input #00
[A,B,3] [B,C,5] [C,D,2]
A->D,10Sample Output #00
A->B->C->DSample Input #01
[A,B,3] [A,C,7] [C,D,2] [B,C,5]
A->D,10Sample Output #01
A->C->DSample Input #02
[A,B,5] [A,C,2] [B,C,4] [B,D,6] [C,B, 7]
A->C,10Sample Output #02
E2Output #2 Explanation
The last edge [C,B,7] on the line is a re-definition (duplication) of a previously defined edge [B,C,4]. Such duplication should result in a logical input error.
I can choose between C++ and Java. This is the default input for Java:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
}
}