I tried the below approach and it worked!!
We want to reach vertex 2 from 1.
What now I do is, scan the adjacency matrix in a column-wise fashion and now I determine the shortest edge by which I can reach a vertex i in the graph.
Like, to reach vertex 2, I can reach with a minimum cost from vertex 4 with cost 3.
Following the similar pattern, I build a path tree, which goes from vertex 1 to vertex 2.
Now, this path from vertex 1 to 2 consist of 4 edges but I want a path with at most 3 edges.
So, now using vertex 1 as source and other vertices 0,3,2 I multiplex them one by one and check which one will give me the shortest path.
And cost comes out to be 8.