Thanks for your time
Awaiting your response :D
if(it1.first+1 + it2.first<=k)temp[ max(it1.first+1 , it2.first) ]+=it1.second*it2.second;
I have a doubt that as i understand we are adding new subtree to our main tree to create posible tree combinations and it1.first is having depth of tree being added and it2.first contains height of tree to which it1 is being added (i.e. root of it2 subtree is going to be the child of root of it1 subtree). So i understand that we are storing temp.first as max(it1.first+1 , it2.first) as we want to store depth of resulting tree but shouldn't the if statement condition be if(it1.first + it2.first<=k) as for getting diameter we already have root of resulting tree included in depth of it2 ?
Also it would be great if you can elaborate the hints little further.
Besides that really good code, easier to understand than editorial method.