码迷,mamicode.com
首页 > 其他好文 > 详细

Graph Theory

时间:2019-08-08 19:33:53      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:row   cee   with   EAP   find   span   limit   new   when   

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)\).

Graph Theory

标签:row   cee   with   EAP   find   span   limit   new   when   

原文地址:https://www.cnblogs.com/mangoyang/p/11323020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!