Advertisement
tinyevil

Untitled

Mar 29th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. 1. Convert to the DAG by merging together nodes in the same strongly connected component in a supernode.
  2. 2. If there are two or more leaf supernodes, output any one node from two different leaf supernodes.
  3. 3. Otherwise, remove the leaf supernode from the graph and repeat (2)
  4. 4. Otherwise, there is no such pair.
  5.  
  6. Suppose the algorithm finds (A,B). If they became leaves at some point, there is no path from A to B, as algorithm removes nodes in a topological order (so no path can go into the removed part of the graph and back).
  7.  
  8. If at some step there is only one leaf supernode X, no node N from X can be part of an answer, as there is a path from each other node to N. Removing edges from the graph never invalidates a correct answer: if (A,B) is an answer for G, then it is also a valid answer for G minus edge E. So we can't lose any answer by removing a leaf supernode X.
  9.  
  10. As graph is a DAG, there are always leaf nodes.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement