Union-Find/Disjoin-Set data structure for Directed Graph

孤人 提交于 2019-12-13 15:25:50

问题


I'm looking for an efficient Union-Find (aka Disjoint Set) data structure for my directed graph, which has cycles and forests. Given such a graph G , I want to to answer following queries:

  1. Can I reach node v from u?
  2. From which nodes, u is not reachable?

For a single "source" node u, I can run DFS search and answer whether I can reach v from it. A single DFS search will have an upper-bound cost of m + n in the worst-case, where m and n are the number of vertices and edges in the graph, respectively. However, I have many such "source" nodes and I'm wondering whether there's a better approach than running DFS separately from all m "source" nodes (which has an upper-bound cost of m * (m + n) in the worst case.)

It seems like both of these questions could be efficiently answered by an Union-Find data-structure for directed graph. To my surprise, I could not find any solution after significant online searches. Am I thinking the problem in wrong direction?

I've found this answer but could not comprehend it.

来源:https://stackoverflow.com/questions/44789738/union-find-disjoin-set-data-structure-for-directed-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!