MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / dfs

Function dfs

graphs/finding_bridges.py:80–94  ·  view source on GitHub ↗
(at, parent, bridges, id_)

Source from the content-addressed store, hash-verified

78 visited = [False] * n
79
80 def dfs(at, parent, bridges, id_):
81 visited[at] = True
82 low[at] = id_
83 id_ += 1
84 for to in graph[at]:
85 if to == parent:
86 pass
87 elif not visited[to]:
88 dfs(to, at, bridges, id_)
89 low[at] = min(low[at], low[to])
90 if id_ <= low[to]:
91 bridges.append((at, to) if at < to else (to, at))
92 else:
93 # This edge is a back edge and cannot be a bridge
94 low[at] = min(low[at], low[to])
95
96 bridges: list[tuple[int, int]] = []
97 for i in range(n):

Callers 1

compute_bridgesFunction · 0.70

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected