import copy
from collections import deque
def hasPath(Gf, s, t, path):
# BFS algorithm
V = len(Gf)
visited = list(range(V))
for i in range(V):
visited[i] = False
visited[s] = True
queue = deque([s])
while queue:
temp = queue.popleft()
if temp == t:
return True
for i in range(V):
if not visited[i] and (Gf[temp][i] > 0):
queue.append(i)
visited[i] = True
path[i] = temp # record precursor
return visited[t]
def bfs(adj, start):
b=[]
if start is None:
return
visited = set()
queue = []
queue.append(start)
visited.add(start)
b.append(start)
while len(queue) > 0:
cur = queue.pop(0)
if cur in adj.keys():
for nex in adj[cur]: #访问其邻接的所有节点
if nex not in visited:
visited.add(nex)
python算法有向图的最大流和最小割及割边输出
最新推荐文章于 2023-06-12 18:45:09 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)