you give tree consist exactly n vertex Tree connect undirected graph n1 edge each vertex v tree value a_v assign itLet distx y distance vertex x y the distance vertex number edge simple path themlet define cost tree follow value firstly let fix vertex tree let v then cost tree sumlimits_i 1n disti v cdot a_iyour task calculate maximum possible cost tree choose v arbitrarily