Skip to content

Commit 8552594

Browse files
Update check_bipatrite.py
1 parent 7bac59d commit 8552594

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

graphs/check_bipatrite.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ def depth_first_search(node: int, color: int) -> bool:
7777
"""
7878
if visited[node] == -1:
7979
visited[node] = color
80+
if node not in graph:
81+
return True
8082
for neighbor in graph[node]:
8183
if not depth_first_search(neighbor, 1 - color):
8284
return False
8385
return visited[node] == color
8486

8587
visited: defaultdict[int, int] = defaultdict(lambda: -1)
86-
for node in list(graph):
88+
for node in graph:
8789
if visited[node] == -1 and not depth_first_search(node, 0):
8890
return False
8991
return True

0 commit comments

Comments
 (0)