def _check_rec(self, fwg: FwGraph, visited: list, cur: int) -> bool: if visited[cur]: return True # we are in a loop if fwg.exits_at(cur): return False visited[cur] = True for n in fwg.next[cur]: if self._check_rec(fwg, visited, n): return True return False
def _check_rec(self, fwg: FwGraph, visited: list, cur: int) -> bool: if visited[cur]: return False # we are in a loop if fwg.exits_at(cur): return True # traffic reaches its destination if len(fwg.next[cur]) == 0: return False # we have a black hole visited[cur] = True for n in fwg.next[cur]: if not self._check_rec(fwg, visited, n): return False return True
def _check_rec(self, fwg: FwGraph, visited: list, cur: int, n_traversed: int) -> bool: if visited[cur]: return False # we are in a loop if fwg.exits_at(cur): return n_traversed == self.len if len(fwg.next[cur]) == 0: return n_traversed == self.len # black hole (whether to ever return true here is arguable) visited[cur] = True for n in fwg.next[cur]: if not self._check_rec(fwg, visited, n, n_traversed + 1): return False return True
def _check_all_traverse_waypoint(self, fwg: FwGraph, visited: list, on_current_path: list, cur: int) -> bool: if cur == self.waypoint: return True elif fwg.exits_at(cur): return False if visited[cur]: if on_current_path[cur]: return False # we have a loop return True if len(fwg.next[cur]) == 0: return False # we have a black hole visited[cur] = True on_current_path[cur] = True for n in fwg.next[cur]: if not self._check_all_traverse_waypoint(fwg, visited, on_current_path, n): return False on_current_path[cur] = False return True