Given an undirected(no lengths) graph G=(V,E) with |V|=n and |E|= m, and two vertices v,w, find the algorithm that outputs the number of shortest v-w-paths in G. The running time should be O(m+n)
I have been working with this problem but have difficulties to let the running time be O(m+n)
Since this graph is both undirected and unweighted, I have tried this way. Use BFS to determine the length of the shortest v-w-path. Then use DFS to find the number of the v-w-shortest paths such that two nodes are connected and the length of path equals to the output of BFS. But the running time of this plan is O(m+n)+O(m+n).
Also I've tried to modify the Dijkstra algorithm. Store the length of the shortest path and the number of the shortest path when there is a node adding to the set of visited nodes. And I 'm stuck with the computation of running time.