MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / dfs

Method dfs

Weekly Contest 179/p4/Solution.cpp:30–43  ·  view source on GitHub ↗

p -> possibility to reach this node `id`

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected