8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 247c359 commit 6816597Copy full SHA for 6816597
graphs/undirected_graph_matrix.py
@@ -102,26 +102,24 @@ def bfs(self):
102
def is_bipartite(self):
103
"""
104
Returns true if graph is bipartite
105
- :return:
+ :rtype: bool
106
107
- is_bipartite = True
108
colorings = {}
109
to_visit = queue.Queue()
110
to_visit.put(0)
111
colorings[0] = 0
112
113
- while not to_visit.empty() and is_bipartite:
+ while not to_visit.empty():
114
v = to_visit.get()
115
116
for u in self.get_neighbor(v):
117
if u not in colorings:
118
colorings[u] = 1 - colorings[v]
119
to_visit.put(u)
120
elif colorings[u] == colorings[v]:
121
- is_bipartite = False
122
- break
+ return False
123
124
- return is_bipartite
+ return True
125
126
127
def get_test_graph_1():
0 commit comments