Skip to main content
fixed typs
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284

From the first line I get: n = 4, m = 5, A = 1, B = 13. 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 output I must receive the length of the shortest path or -1 if the path doesn't existsexist.

From the first line I get: n = 4, m = 5, A = 1, B = 1. 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 output I must receive the length of the shortest path or -1 if the path doesn't exists.

From the first line I get: n = 4, m = 5, A = 1, B = 3. 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 output I must receive the length of the shortest path or -1 if the path doesn't exist.

deleted 25 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

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.

So, from first line I get: n = 4, m = 5, A = 1, B = 1. Than I get 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 output I must receive the length of the shortest path or -1 if the path doesn't exists.

Here is my solution using Dijkstra's algorithm:

I know, that Dijkstra is the fastest algorithm for searching the shortest path from one vertex to all anothers vertices, but I my case it works too long.

  • How can I optimize this code to make it working faster (this is the main problem)?
  • If you see some bugs in this snippet, please, let me know.

Thanks.

From the first line I get: n = 4, m = 5, A = 1, B = 1. 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 output I must receive the length of the shortest path or -1 if the path doesn't exists.

Here is my solution using Dijkstra's algorithm:

I know that Dijkstra is the fastest algorithm for searching the shortest path from one vertex to all other vertices, but in my case it takes too long.

  • How can I optimize this code to make it working faster (this is the main problem)?
  • If you see some bugs in this snippet, please, let me know.
added 31 characters in body
Source Link
VeLKerr
  • 133
  • 6
  • 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.
  • How can I optimize this code to make it working faster?
  • If you see some bugs in this snippet, please, let me know.
  • How can I optimize this code to make it working faster (this is the main problem)?
  • If you see some bugs in this snippet, please, let me know.
Source Link
VeLKerr
  • 133
  • 6
Loading