So, fromFrom the first line I get: n = 4, m = 5, A = 1, B = 1.
Than Then I get the elements of the adjacency list. The first number in each line is from-vertex, the second - to-vertex, and the last is the weight of current edge. 0 or 1.
In the outputoutput I must receive the length of the shortest path or -1 if the path doesn't exists.
Here is my solutionsolution using Dijkstra's algorithm:
I know, that Dijkstra is the fastest algorithm for searching the shortest path from one vertex to all anothersother vertices, but Iin my case it works too longtakes too long.
- How can I optimize this code to make it working fasterworking faster (this is the main problem)?
- If you see some bugs in this snippet, please, let me know.
Thanks.