我正在寻找一种方法,给定有向图,找到从给定起点无法到达的所有节点。我有一个想法,基于与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