Problem Statement
Game Routes
Implementation
void solve() {
ll n, m;
cin >> n >> m;
vvll v(n);
rep(i, m) {
ll x, y;
cin >> x >> y;
--x, --y;
v[x].pb(y);
}
vll topo, vis(n, 0);
function <void(ll, ll)> dfs = [&](ll node, ll pr) {
vis[node] = 1;
for (auto& child : v[node]) {
if (!vis[child]) dfs(child, node);
}
topo.pb(node);
};
dfs(0, 0);
reverse(all(topo));
vll dp(n, 0);
dp[0] = 1;
for (auto& node : topo) {
for (auto& child : v[node]) {
dp[child] += dp[node];
dp[child] %= mod;
}
}
cout << dp[n - 1] << "\n";
}