|
|||
The Fastest Road to Banikoara
Codjo: I am ready for the trip to Banikoara. Bossi: Let us go through Parakou. Assiba: No, the fastest road to go to Banikoara is through Djougou. Your task is to write a program which, given a list of towns and distances between these towns, gives the shortest distance to travel from a town A to a town B. Input Specification
The first line of the input contains a single integer P
(1 ≤ P ≤ 1000), which is the number of data sets
that follow. Each data set begins with a line containing the number N of the
remaining lines in the data set (1 ≤ N ≤ 500),
followed by a space, followed by the name of the departure town, followed by a space,
followed by the name of the destination town. Each of the next N lines contains the
names of two towns separated by a space, followed by a space, followed by the distance (in
kilometers) between the two towns. The distance will be an integer, and the town names will
be strings consisting of uppercase and lowercase English letters and hyphens
(“ Output SpecificationFor each data set, you must generate a single output line containing the name of the departure town, followed by a space, followed by the name of the destination town, followed by a space, followed by the shortest distance to travel between the two towns. Sample Input
Output for Sample Input
|
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |