Mistake : Running BFS from every node to find diameter. That is . Use two-BFS instead. Mistake : Thinking diameter always passes through the root. It does not. The longest path can be anywhere in the tree. Mistake : Forgetting to handle both diameter endpoints in Tree Distances I.
You need the max of distances to both endpoints. Mistake : Trying to solve Tree Distances II with BFS from each node. That times out. Use rerooting DP.