Thank you for the explanation. As a small optimisation you can also return early if one of the queries results in a shortest path of 1. In that case res would have to be initialised with size q and value 1 on declaration.
I’m big fan of ur work but this time I think there is a tips to do it more simply perhaps with indexes who can give you the direct distances… I need to dive in
I did it using adjacency matrix instead of list. Is that the reason why my solution takes a lot of runtime? (Ik Leetcode runtimes are not worth trusting, but assuming it would atleast be somewhat accurate)
Matrix is good for dense graph while list is good for other sparser types. Since, most test cases are not dense hence your runtime must have been higher.
Thank you for the explanation. As a small optimisation you can also return early if one of the queries results in a shortest path of 1. In that case res would have to be initialised with size q and value 1 on declaration.
Thank you sir :)
welcome :)
Thankyou sir
welcome :)
I’m big fan of ur work but this time I think there is a tips to do it more simply perhaps with indexes who can give you the direct distances… I need to dive in
Yes
thanks
Welcome
thankyou sir i want to build solid logic like you any suggestions pls do give
Practice more and you'll build a strong logic over time.
getting time limit exceeded on normal bfs sir!! what optimisation can be done??
I have also applied normal BFS. Can you please check once if your loop is breaking properly.
I did it using adjacency matrix instead of list. Is that the reason why my solution takes a lot of runtime? (Ik Leetcode runtimes are not worth trusting, but assuming it would atleast be somewhat accurate)
Matrix is good for dense graph while list is good for other sparser types. Since, most test cases are not dense hence your runtime must have been higher.