问题
Suppose that we have an n-node, m-edge undirected graph G = (V; E) and we have two distinct nodes called s and t. Suppose that the distance between s and t is strictly greater than n/2 . Show that there is a node v which is dierent from s and t such that every path from s to t goes through v. Give an algorithm with running time O(n + m) to nd such a vertex. You do not have to prove that your algorithm is correct but you must give a proof that a vertex like v exists.
I can not figure out an exact answer to this past paper question, help me out!
回答1:
Suppose there are two paths between s and t, that don't share a node. Since distance between s and t is > n/2, than each path has >= n/2 nodes between s and t. That means that graph has >= n+2 nodes, what is a contradiction.
For algorithm it is enough to find any path and than see where sub-graph that is connected to one side (s) without using path nodes finish. In more details:
- if s is connected only to one node than that node we are looking for.
- if not, make BFS from s
- find path s-t
- find nodes connected to s without using edges going from nodes of path s-t
- last node on path s-t that is in connected part is node we are looking for.
来源:https://stackoverflow.com/questions/19173736/undirected-graphs-algorithms