Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def BFS(G, s):
- # G to macierz opisująca graf: G[i][j]==1 jeśli jest
- # wierzchołek z i do j. W przeciwnym razie G[i][j]=0
- # s to numer wierzchołka źródłowego
- noV = len(G[0])
- visited = [False for i in range(noV)]
- path = [[None, 0] for i in range(noV)]
- Q = Queue()
- for v in range(noV):
- if not visited[v]:
- Q.put(v)
- while not Q.empty():
- u = Q.get()
- for s in range(noV):
- if (G[u][s] == 1 and not visited[s]):
- visited[s] = True
- path[s] = [u, path[u][1]+1]
- Q.put(s)
- return path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement