HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


50464 - From Tirana to Durres

Guest
• Review clarifications (1)

Volume problems

• 50674 - Collecting Eggs
• 50306 - Beautiful Numbers
• 50411 - Sum of the Leaves
• 50675 - Kruja Boys
• 50421 - Repairing road segments
• 50736 - Top N Donors - 2
• 50775 - Balanced Parenthesis
• 50774 - Hot Potato
• 50464 - From Tirana to Durres
• 50757 - National Elections - 1
• 50681 - Center of a Series
• 50753 - Average of the Nth Student
• 50735 - Top M Products
• 50795 - Trunk

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

From Tirana to Durres

Question:
Write a program that finds the shortest path between any two given cities in a directed graph G.

Input specification
The first line contains a number (E) which represents the number of edges Then in the following E lines, it writes the name of two cities (city1 and city2) and an integer number d which means there is a path from the first city (city1) to the second one (city2) with the given distance (d).

At the last line of the input, you will be given the names of two cities (srcCity, destCity). You will find the shortest path from the srcCity to destCity (, if there is any) where 1 ≤ n ≤ 60

Output specification
Show the distance between city1 and city2 if there exists a path. If there is no path show -1.

Sample Input I   
12
Tirana Elbasan 2
Tirana Vlora 4
Tirana Peshkopia 1
Elbasan Peshkopia 3
Elbasan Fier 10
Vlora Durres 5
Peshkopia Vlora 2
Peshkopia Durres 8
Peshkopia Kavaja 4
Fier Peshkopia 2
Fier Kavaja 6
Kavaja Durres 1
Tirana Durres

Sample Output I   
6


Для отправки решений необходимо выполнить вход.

www.contester.ru