#3203

Find Minimum Diameter After Merging Two Trees

expert · 1250 · lc hard +32 · 57.1% accepted · 695 likes · top 52%

Description

Two undirected trees are given: one with n nodes and edge list edges1, another with m nodes and edge list edges2.

Add one edge connecting a node from the first tree to a node from the second tree.

Return the minimum possible diameter of the resulting merged tree.

The diameter of a tree is the length of the longest path between any two nodes.

Code

1
2
3