jeudi 27 mai 2010

Check if a graph is bipartite


setA
setB
bipa = True
for e in edges
if e0 in setA
if e1 in setB
continue
elif e1 in setA
bipa = False
break
else
put e1 in setB

elif e0 in setB
if e1 in setA
continue
elif e1 in setB
bipa = False
break
else
put e1 in setA

else
if e1 in setA
put e0 in setB
elif e1 in setB
put e0 in setA
else
put e0 in setA
put e1 in setB

Aucun commentaire:

Enregistrer un commentaire