CodeLab Academy 📞 9936 6696
← List Python · Level 10: Algorithms Code · 100 points ← #958 #960 →

#959. Shortest path (Dijkstra)

You get n vertices and m undirected weighted edges. Find the length of the shortest path from vertex 1 to vertex n. If n cannot be reached, print -1. ### Input n m, then m lines `u v w`. ### Output A number.

Examples

Input
5 4
1 5 11
2 4 8
5 2 10
2 5 12
Output
11
Input
2 4
2 2 12
2 1 14
1 1 2
1 1 9
Output
14

💡 You can solve it with Python, JavaScript or blocks. Read the input line by line with input(). Don't print a question (like input("Number: ")). Print exactly what the output asks for, nothing more.

🔒 You can solve the first 3 problems without an account. Sign up for free to solve this one!