Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Run a Dijkstra from node numbered n to compute distance from the last node.
Consider all edges [u, v] one by one and direct them such that distance of u to n > distance of v to n. If both u and v are at the same distance from n, discard this edge.
Now this problem reduces to computing the number of paths from 1 to n in a DAG, a standard DP problem.