Ajob Commute II

Once again we return to Ajobshohor, the capital city and the heart of Ajobdesh. Ajobshohor’s road system can be represented as a tree. There are n tollbooths, connected with n - 1 roads. Each tollbooth has an x-factor associated with it. The government has issued a new regulation, where every person traveling via that tollbooth has to pay an amount which is determined by a formula of F(x). However, the government can reissue the x-factor associated with any tollbooth, and update it in a single day.


This is a companion discussion topic for the original entry at https://toph.co/p/ajob-commute-ii