Legend goes that in the heart of ocean, exists a gorgeous island called LaTale, which has n cities. Specially, there is only one way between every two cities. In other words, n cities construct a tree connected by n-1 edges. Each of the edges has a weight w. Define d the length between city u and city v. Under the condition of u differing from v, please answer how many pairs in which d can be divisible by 3. Pair(u,v) and pair(v,u) are considered the same.
Legend goes that in the heart of ocean, exists a gorgeous island called LaTale, which has n cities. Specially, there is only one way between every two cities. In other words, n cities construct a tree connected by n-1 edges. Each of the edges has a weight w. Define d(u, v) the length between city u and city v. Under the condition of u differing from v, please answer how many pairs(u, v) in which d(u, v) can be divisible by 3. Pair(u,v) and pair(v,u) are considered the same.