This is the question: Given a directed graph G=(V,E), a source vertex s $epsilon V, we know that all cycles in G are of positive weight ( > 0). Also we are given the graph after Bellman-Ford was run on it, meaning that for each v in V we know both d[v] (shortest path from s to v) and pi[v] (v's predecessor)
Describe an algorithm to find the number of shortest path from s to v for all v in V. The algorithm must run in O(V+E)
*We cannot edit the Bellman-Ford run on the algorithm
This is what i thought of: We run a modified DFS,
Algorithm(G,s):
1.DFS-Visit(G,s)
2. return count[v] foreach v in V
DFS-Visit(G,u):
1.foreach v in Adj[u]
2.if d[v] == d[u] + w(u,v) && (u,v) is not a backedge
3.count[v] = count[v] + 1
4.DFS-visit(G,v)
*It seems like the algorithm can get stuck in an infinite loop, maybe i can ignore back-edges? (since a shortest path will always be simple)
*This is not a duplicate of How to find the number of different shortest paths between two vertices, in directed graph and with linear-time?
in that question the graph is unweighted here it is weighted ( edges) Do you think this is correct? Thanks