Run Kahn's algorithm to get the topological order of the levels.
Initialize ways[1] = 1 and all other ways[i] = 0.
Process levels in topological order.
For each level : For each neighbor where edge exists: ways[v] = (ways[v] + ways[u]) % 10^9 + 7.
After processing all levels, the answer is ways[n].
Why modulo? Because the number of paths can be exponentially large. The problem asks for the result modulo to keep numbers manageable.
This runs in time and uses space.