Because the original graph is a DAG, the filtered graph is also a DAG, so we can compute shortest paths in linear time using a topological order DP (no need for Dijkstra). Algorithm Build adjacency ...