Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def opposite(i):
- if i == 0:
- return 1
- if i == 1:
- return 0
- def BFS(G,s):
- n = size(G)
- reached = []
- color = []
- for i in range(n):
- reached.append(False)
- color.append(-1)
- tobeConsidered = [s]
- color[s] = 0
- reached[s] = True
- T = []
- i = 0
- while i < len(tobeConsidered):
- k = tobeConsidered[i]
- V = neighbors(G,k)
- for [j,w] in V:
- if color[j] == -1:
- color[j] = opposite(color[k])
- elif color[j] == color[k]:
- return False
- if reached[j] == False:
- T.append([k,j])
- reached[j] = True
- tobeConsidered.append(j)
- i = i+1
- return True
Add Comment
Please, Sign In to add comment