p -> possibility to reach this node `id`
| 28 | |
| 29 | // p -> possibility to reach this node `id` |
| 30 | void dfs(int id, double p, int round_left) { |
| 31 | if (round_left == 0) { // cannot travel any farther |
| 32 | if (id == target) this->p = p; |
| 33 | return; |
| 34 | } |
| 35 | int childn = getchildn(id); |
| 36 | if (id == target and childn == 0) { // reach target and nowhere else to go |
| 37 | this->p = p; |
| 38 | return; |
| 39 | } else if (id == target or childn == 0) return; |
| 40 | p /= childn; |
| 41 | for (int cid : ut[id]) |
| 42 | dfs(cid, p, round_left-1); |
| 43 | } |
| 44 | |
| 45 | double frogPosition(int n, vector<vector<int>>& edges, int t, int target) { |
| 46 | visited.resize(n+1, false); |
nothing calls this directly
no outgoing calls
no test coverage detected