I'm trying to find all possible paths from source to destination in a directed graph where edges have weight. There exist cycles but should not lead to infinite loops.
I have used BFS but was unable to detect cycles so that I can consider them as well in the routes.
For example I have the following adjacency list:
'C':['D','E']
'D':['E','C']
'E':['B']
'B':['C']
For source being 'C' and destination being 'C' too, assuming that paths should be no longer than 4 stops, I would have the following routes as result:
CDC CEBC
遍历图形时,请尝试将边标记为已访问,而不是将顶点标记为已访问。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.