Skip to content

Commit f3bb54f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 3f3c8cb commit f3bb54f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: graphs/check_bipartite_graph_all.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import defaultdict, deque
22

3+
34
def is_bipartite_dfs(graph: defaultdict[int, list[int]]) -> bool:
45
"""
56
Check graph bipartite using DFS.
@@ -18,6 +19,7 @@ def is_bipartite_dfs(graph: defaultdict[int, list[int]]) -> bool:
1819
>>> is_bipartite_dfs(defaultdict(list, {0: [1, 2], 1: [0, 2], 2: [0, 1]}))
1920
False
2021
"""
22+
2123
def dfs(node, color):
2224
"""
2325
DFS starting from a node.
@@ -48,6 +50,7 @@ def dfs(node, color):
4850
return False
4951
return True
5052

53+
5154
def is_bipartite_bfs(graph: defaultdict[int, list[int]]) -> bool:
5255
"""
5356
Check graph bipartite using BFS.
@@ -82,6 +85,7 @@ def is_bipartite_bfs(graph: defaultdict[int, list[int]]) -> bool:
8285
return False
8386
return True
8487

88+
8589
if __name__ == "__main":
8690
import doctest
8791

Diff for: graphs/check_bipatrite.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import defaultdict, deque
22

3+
34
def is_bipartite_dfs(graph: defaultdict[int, list[int]]) -> bool:
45
"""
56
Check if a graph is bipartite using DFS.
@@ -19,6 +20,7 @@ def is_bipartite_dfs(graph: defaultdict[int, list[int]]) -> bool:
1920
>>> is_bipartite_dfs(defaultdict(list, {0: [1, 2], 1: [0, 3], 2: [0, 1]}))
2021
False
2122
"""
23+
2224
def dfs(node, color):
2325
"""
2426
Perform Depth-First Search (DFS) on the graph starting from a node.
@@ -43,6 +45,7 @@ def dfs(node, color):
4345
return False
4446
return True
4547

48+
4649
def is_bipartite_bfs(graph: defaultdict[int, list[int]]) -> bool:
4750
"""
4851
Check if a graph is bipartite using BFS.
@@ -77,6 +80,8 @@ def is_bipartite_bfs(graph: defaultdict[int, list[int]]) -> bool:
7780
elif visited[neighbor] == visited[curr_node]:
7881
return False
7982
return True
83+
84+
8085
if __name__ == "__main":
8186
import doctest
8287

@@ -85,4 +90,4 @@ def is_bipartite_bfs(graph: defaultdict[int, list[int]]) -> bool:
8590
if result.failed:
8691
print(f"{result.failed} test(s) failed.")
8792
else:
88-
print("All tests passed!")
93+
print("All tests passed!")

0 commit comments

Comments
 (0)