NewThe Learning module is now liveSee what's new

You are given an undirected connected graph that forms a tree with n nodes, labeled from 0 to n - 1. The graph is described by two integer arrays, treeFrom and treeTo (each of length n - 1), where each treeFrom[i] and treeTo[i] together specify an undirected edge between those two nodes.

For any two nodes u and v, the distance dist(u, v) is defined as the number of edges on the unique path connecting them.

Test Cases
Input
Output
Expected