Created
September 2, 2019 02:46
-
-
Save alexgolec/8e24f8eee5ff34e184e3ae0fdd8b9088 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def __dfs_helper(rate_graph, node, end, rate_from_origin, visited): | |
if node == end: | |
return rate_from_origin | |
visited.add(node) | |
for unit, rate in rate_graph.get_neighbors(node): | |
if unit not in visited: | |
rate = __dfs_helper(rate_graph, unit, end, rate_from_origin * rate, visited) | |
if rate is not None: | |
return rate | |
return None | |
def dfs(rate_graph, node, end): | |
return __dfs_helper(rate_graph, node, end, 1.0, set()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment