在给定有向图的情况下,我正在寻找一种方法来查找从给定起点无法到达的所有节点。我有一个想法,基于与 Dijkstra 算法类似的概念,就像这样(伪代码),但有更好的方法吗?
function DisconnectedNodes(Graph, Start)
var Unknown = new list
var Open = new list
var Closed = new list
for each Node in Graph
Unknown.add(Node)
Open.StealFrom(Unknown, Start)
while Open.Count > 0
var Current = Open[0]
for each Node in Current.Destinations
if Node in Unknown
Open.StealFrom(Unknown, Node)
Closed.StealFrom(Open, Current)
return Unknown