Educational Codeforces Round 36 F - Imbalance Value of a Tree

Problem - F - Codeforces 問題 $n$ 頂点の木が与えられる。また頂点 $i$ には整数 $a_i$ が書かれている。 $I(x, y)$ を「 $xy$ パス上の頂点の中での、 $a_i$ の最大値と最小値の差」と定める。