149. Computer Network
time limit per test: 0.25
memory limit per test: 4096
input: standard input
output: standard output
A school bought the first computer some time ago. During the recent years the school bought N-1 new computers. Each new computer was connected to one of settled earlier. Managers of school are anxious about slow functioning of the net and want to know for each computer number Si - maximum distance, for which i-th computer needs to send signal (i.e. length of cable to the most distant computer). You need to provide this information.
There is natural number N (N<=10000) in the first line of input, followed by (N-1) lines with descriptions of computers. i-th line contains two natural numbers - number of computer, to which i-th computer is connected and length of cable used for connection. Total length of cable does not exceed 10^9. Numbers in lines of input are separated by a space.
Write N lines in output file. i-th line must contain number Si for i-th computer (1<=i<=N).
|Author:||Andrew V. Lazarev, Michael R. Mirzayanov
|Resource:||Saratov Subregional School Team Contest, 2002
|Server time: 2016-06-25 01:12:11||Online Contester Team © 2002 - 2016. All rights reserved.|