从根到所有顶点中找到定向图中给定长度的所有路径
首先,如果我犯了任何英语错误,对不起。
我需要找到 n
length(例如4个顶点)的所有路径,仅从开始代码>。我使用C ++,无法更改语言。我使用Boost Graph库,并试图在没有成功的情况下了解他们的DFS访问者概念。
我什至接受“ 4K 2048 RAW”的路径 - > “ 4K 2048 RAW” - > “ 4K 2048 RAW” - >例如,“ 4K 2048 RAW”
。
我使用像发电机一样的图。如果有人有或没有BGL的解决方案,请感谢您。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不发布图表,并保存您的答复器10分钟的生命:
比较结果在线a>。
使用BGL,
您可以,但我怀疑这确实有用,因为您描述的算法不容易存在,或者在BFS/DFS访问者上实施它会效率低下。这就是创建匹配
acchacency_list
:实时在wandbox
打印
呈现为相同
应用
depth_first_visit
实际上对我们没有帮助,因为它不会访问两次顶点,因此您只能获得最小的路径子集:live on Compiler Explorer上
库(
使用标准库使用标准
和libfmt)(和libfmt)(和自libfmt in Standard-formatting尚未进行)在标准中):
live in Compiler Explorer上
输出“ https://godbolt.org/z/t6e7wjpqv” rel =“ nofollow noreferrer”>
length == 3
Why not post the graph, and save your answerers 10 minutes of their life:
Compare the result online.
With BGL
You can, but I doubt it is really helpful as the algorithm you describe doesn't readily exist, or implementing it on the BFS/DFS visitors will be inefficient. Here's what it would look like to create a matching
adjacency_list
:Live On Wandbox
Prints
Which renders to the same
Note that I'm not even attempting to implementing the path search at this time.Applying
depth_first_visit
doesn't really help us, because it doesn't visit any vertex twice, so you get only a minimal subset of the paths you're after:Live On Compiler Explorer
Prints
Bespoke Using Standard Library
Using just the standard library (and libfmt since range-formatting is not yet in the standard):
Live On Compiler Explorer
Output for
length == 3
使用深度优先搜索(DFS)的算法
Algorithm using depth first search ( DFS )