I have got the solution for small p by calculating Dist [u] [i] for i=0 to p-1 using Dijkstra.. how to solve it such that the solution is independent of the value of p.
https://leetcode.com/tag/graph https://leetcode.com/tag/dynamic-programming https://hackerearth.com