Graph Theory

假装没事ソ 提交于 2019-11-26 13:57:32

Shortest Path - Tree

Description:

​ Directed edge \((u,v)\) in tree if \(u\) last relax \(v\) , the root is \(S\) or \(T\) .

The classic problem :

​ forall edge \(i\) in the Graph , query the shortest path \((S, T)\) without edge \(i\) .

Solution:

​ If edge \(i\) not in the shortest path, the answer is distance\((S, T)\) .

​ Otherwise , build the shortest path-tree (the root is S). we can prove the shortest path must have only one non-tree-edge, assume edge \(i= (u,v)\) , we can find an optimal non-tree-edge \((x, y)\) that the Graph have least one path \((S, x)\) and path \((y, T)\) without edge \(i\) , the new path is \((S\rightarrow x\rightarrow y\rightarrow T)\) , and the additional value is distance\((S, x)\) \(+\) weight\((x,y)\) \(-\) distance\((S, y)\) . Obviously, We need minimum the additional value, we can enumerate the non-tree-edge to calculate answer in \(\mathcal O(m)\) complexity.

K-shortest Path

Description:

​ The k'th Shortest Path in the Graph.

Solution:

  1. Use A* algorithm and get timelimit exceed.
  2. Do some classic work in Shortest-Path tree (\(T\) is root), The path \((S, T)\) must consist of some tree-edge and non-tree-edge. The non-tree-edge\((x,y)\) 's additional value is distance\((y, T)\) \(+\) weight\((x,y)\) \(-\) distance\((x, T)\) . The problem transfrom to a new problem, get k-mininal sequence which consist of non-tree-edge. So we can use heap to maintain vertex and the sum of non-tree-edge value, the k'th be popped node is answer. When node \(x\) be popped, expand all non-tree-edge in the treepath$(x, T) $,the complexity is \(\mathcal O(kmlogn)\) .
  3. According to solution 2, we can get a better solution. Obviously, when node \(x\) be popped, choose smallest non-tree-edge must better than choose second smallest non-tree-edge. So we can add a new situation to indicate which ranking non-tree-edge has been considered. When node \(x\) be poped, just consider next non-tree-edge or transfrom to another vertex. To maintain non-tree-edge ranking in the path,. we need use chairman's tree or mergeable heap . This solution's complexity is \(\mathcal O(k\ log n+m\log n)\).
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!