A bipartite graph is a graph whose vertices can be divided into two disjoint set, such that no edge connects two vertices in the same set. A graph is bipartite if and only if it is 2-colorable.
Challenge
Your task is to, given the adjacency matrix of an undirected simple graph, determine whether it is a bipartite graph. That is, if an edge connects vertices i and j, both (i, j) and (j, i) entry of the matrix are 1.
Since the graph is undirected and simple, its adjacency matrix is symmetric and contains only 0 and 1.
Specifics
You should take an N-by-N matrix as input (in any form, e.g. list of lists, list of strings, C-like int**
and size, flattened array, raw input, etc.).
The function/program should return/output a truthy value if the graph is bipartite, and falsy otherwise.
Test Cases
['00101',
'00010',
'10001',
'01000',
'10100'] : False
['010100',
'100011',
'000100',
'101000',
'010000',
'010000'] : True (divide into {0, 2, 4, 5} and {1, 3})
['00',
'00'] : True
Scoring
Builtins that compute the answer directly are banned.
This is code-golf, so the shortest program (in bytes) by the end of this month wins!
-1
for falsy and any non-negative integer for truthy? \$\endgroup\$0
-> Falsy,>0
-> Truthy is generally allowed by standard truthy/falsy rules.-1
and≥ 0
is not that common, that's why I asked. \$\endgroup\$