# Time Complexity: O(n + e), Space Compleixty: O(n)
class Solution:
def isBipartite(self, graph: List[List[int]]) -> bool:
n = len(graph)
colors = [0] * n
def dfs(u, color) -> bool:
if (colors[u] != 0):
return colors[u] == color
colors[u] = color
for v in graph[u]:
if (not dfs(v, -color)):
return False
return True
for u in range(n):
if (colors[u] == 0 and not dfs(u, 1)):
return False
return True