The number of paths can grow exponentially, easily exceeding . That is why the problem asks for the answer modulo . Take the modulo after every addition: dp[v] = (dp[v] + dp[u]) % (10^9 + 7).
This keeps intermediate values manageable and prevents integer overflow. Do not wait until the end to take modulo. Overflow happens during computation, not in the final answer. Apply modulo at each step.