nnahas wrote:[
Case 2: The minimum diameter spanning tree T has an even diameter d(meaning the longest path has an even number of vertices.)
Mmm, well, this case would be equivalent to the previous one *IF* we could prove that splitting the edge in T that links v (which is defined to be one of the two midpoints of P) to the subtree containing its deepest child would make the diameter equal to d+1. But I am not able to prove it, because nothing tells us that the path P is the shortest path between its extremities in the original graph.
But it is not too hard to slightly change the algorithm so that a correctness proof becomes feasible. Instead of splitting edges, let us adopt the following algorithm (which is only O(N^3) ):
1- Get a BFS Tree for each vertex.
For each such BFS tree do the following
a- Let MaxDist be the maximum distance to the root for any vertex in the BFS Tree
b-Get the list of all nodes that are at a distance MaxDist from the root.
c-Try to find a BFS Tree such that all these nodes are descendants of the same child of v. if such a BFS tree exists , then there is a tree of diameter 2*MaxDist, otherwise all we can say is that there is a tree of diameter 2*MaxDist +1. That value will be an upper bound on the diameter.
the least upper bound will be the diameter of the optimal Tree T..
There are 2 issues to address here : the first is the feasibility of step c, and the second is the correctness of this algorithm.
We can implement step c by precomputing a distance table using Floyd-Warshall. Then for each vertex adjacent to the root we check if all the vertices that are at distance MaxDist from the root are at a distance of MaxDist -1 from the child in question . so step c is definitely feasible.
In fact this algorithm is incredibly easy to implement . 10-15 lines should do it. Will anyone volunteer and do it and tell us if it works ? I would have done it myself but the I/O code is tedious to write ,and I don't have any of it ready as I didn't take part in the contest.
OK, so now the correctness proof :
Once again, let d,T,P ,dist'(i,v) be as defined in my first post on this thread. v is one of the 2 midpoints of P. Then we are sure that only one of the subtrees of T rooted at one of the children of v are has nodes at a distance of d/2, otherwise there would be path of length greater than d joining the deepest vertices of two subtrees (It would be of length d+1) actually. We still have to prove that the existence of T implies the existence of a BFS tree rooted at v having the same property as T (namely that all its deepest nodes are the descendants of the same child of v.)
I'll leave that to a later message. Stay Tuned
