little x tree consist n node number 1 n each edge tree positive length Lets define distance node v u denote dvu sum length edge short path v u a permutation p sequence n distinct integer p1p2pn 1pin Little X wants find permutation p sum maximal possible if multiple optimal permutation want find lexicographically small help task