Graph Theory37 sections · 1633 units
Open in Course

Game Routes - Implementation

Complete solution

Here is the complete solution:

topoOrder = topologicalSort(adj)
dp = array of size n + 1, all 0
dp[1] = 1

for u in topoOrder:
    for v in adj[u]:
        dp[v] = (dp[v] + dp[u]) mod MOD

print dp[n]

Count paths by summing contributions from predecessors.