TaskOnce upon a time, there were N medieval towns in the beautiful Moldavian territory, uniquelynumbered from 1 through N. The town numbered with 1 was the capital city. The towns wereconnected by N-1 bidirectional roads, each road having a length expressed in kilometers. Therewas a unique way to travel between any pair of towns without going through a town twice (i.e.the graph of roads was a tree).When a town was attacked, the situation had to be reported as soon as possible to the capital.The message was carried by harbingers, one of which resided in each town. Each harbinger wascharacterized by the amount of time required to start the journey and by his constant speed(expressed in minutes per kilometer) after departure.The message from a town was always carried on the unique shortest path to the capital. Initially,the harbinger from the attacked town carried the message. In each town that he traversed, aharbinger had two options: either go to the next town towards the capital, or leave the messageto the harbinger from this town. The new harbinger applied the same algorithm as above.Overall, a message could be carried by any number of harbingers before arriving in the capital.Your task is to find, for each town, the minimum time required to send a message from thattown to the capital.Description of inputThe first line of the input file harbingers.in contains one integer N, the number of towns inMoldavia. Each of the following N-1 lines contains three integers u v d, separated by onespace, describing a road of length d kilometers between towns numbered with u and v.Subsequently, N-1 pairs of integers follow, one per line. The ith pair, Si Vi, describes thecharacteristics of the harbinger in the (i+1)th town: Si is the number of minutes to prepare forthe journey, and Vi is the number of minutes needed to travel one kilometer. There is noharbinger in the capital.
đang được dịch, vui lòng đợi..
