• 1
    Input and Output Data
    • Tasks
  • 2
    Conditions
    • Tasks
  • 3
    For Loop
    • Tasks
  • 4
    Strings
    • Tasks
  • 5
    While Loop
    • Tasks
  • 6
    Lists
    • Tasks
  • 7
    Two-Dimensional Arrays
    • Tasks
  • 8
    Dictionaries
    • Tasks
  • 9
    Sets
    • Tasks
  • 10
    Functions and Recursion
    • Tasks
  • к

Lesson 8. Dictionary

Difficulty level:

Task«Flight time»

💻 Python
The airline provided data on the time of direct flights between different cities. You need to find the minimum flight time between two specified cities, given the possible transplants. Each transplant requires an additional 1 hour. RN
Direct flights are presented in the form of couples "city-city" and the time of flight in the flight in the time hours. If there is no direct flight between the cities, you need to find the optimal route through other cities.

Input format

The first line contains the number of direct flights N. The following n lines contain information about flights in the format "City1 City2 Time". The last line contains cities of departure and destination through a gap

Output format

the minimum time of the flight in the clock or "the route is not found" if it is impossible to get

Example

Input

5
Moscow St. Petersburg 2
Kazan Kazan 3
Moscow Yekaterinburg 4
Yekaterinburg Kazan 2
Kazan Novosibirsk 3
Moscow Novosibirsk

Output

8

Hint

There will be no clue here, decide for yourself!

main.py
Test 1
Test 2
Test 3
Test 4
Test 5
Test 6
Test 7
Test 8
Test 9
Test 10
Developer’s solution

🎉 Congratulations! 🎉

You did an excellent job with the task! It was a challenging problem, but you found the correct solution. You are one step closer to mastering programming! Keep up the good work, because every stage you pass makes you even stronger.

AD

Advertisement

red-snake blue-snake green-snake

Running your code...

AI Helper

Hi! I am your programming assistant. Ask me anything about Python — I can explain functions, methods, and help you understand the current task!