Given an undirected graph, find if it is bipartite or not. Return true or false.
biparty graph = two coloring problem
DFS + coloring customization to implement it
We can do this by marking each node with 0 or 1.The first one we mark with 1, then a node in his list of neighbours with 0, then a neighbour of the neighbour with 1 and so until we mark all the nodes(and return true) or we arrive in a node that is 0 and we want to mark it with 1 or viceversa (and we return false).
时间: 2024-10-09 10:39:56