Tempe5t's blog

By Tempe5t, history, 3 years ago, In English

Hey, I've been trying to solve the following problem and I have no idea how to go further.

You are given 2 weighted undirected trees $$$T_1$$$ and $$$T_2$$$ such that both trees have $$$n$$$ vertices. You have to find the pair of vertices $$$(v, u)$$$ such that the value of $$$f_1(v, u)+f_2(v, u)$$$ is minimal where $$$f_i(v, u)$$$ is the maximum weight on edge on the path from $$$v$$$ to $$$u$$$ in $$$i$$$-th tree (only output the minimal value, no need to output vertices).

$$$n \leq 10^6$$$ and $$$w_i \leq 10^9$$$ (where $$$w_i$$$ is weight on $$$i$$$-th edge)

I thought about converting those trees to Line trees and then doing some D&C but it doesn't seem to work and I have no idea how to go further. I'm rather looking for some hints than a whole solution. Thanks in advance!

  • Vote: I like it
  • +29
  • Vote: I do not like it

| Write comment?
»
3 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I hope it doesn't spoil the solution immediately, but if you have 2 neighbouring nodes $$$u$$$ and $$$v$$$ then let's say they have cost $$$f_1+f_2$$$. Then any pair of nodes whose path goes through $$$u$$$ and $$$v$$$ will have at least the same cost.

  • »
    »
    3 years ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    It doesn't have to be true. While vertices $$$(v, u)$$$ might be neighbouring in $$$T_1$$$ they don't have to be adjacent in $$$T_2$$$. (i.e. structures of both trees are Independent from each other).

»
3 years ago, hide # |
Rev. 2  
Vote: I like it +7 Vote: I do not like it
Hint 1
Hint 2
Hint 3
Solution