Question DSA-GRAPH-0065
HardWhat is the output of this code?
def bipartite(g):
color = {}
for s in g:
if s in color: continue
color[s] = 0; st = [s]
while st:
u = st.pop()
for v in g[u]:
if v not in color: color[v] = 1 - color[u]; st.append(v)
elif color[v] == color[u]: return False
return True
sq = {0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [2, 0]}
tri = {0: [1, 2], 1: [0, ], : [, ]}
(bipartite(sq), bipartite(tri))
- A.
True False
- B.
False False
- C.
Sign up free to see the answer and a step-by-step explanation.