#P10962. Computer

Computer

题目描述

A school bought the first computersome time ago(so this computer's id is 1). During the recent years the schol bought N-1 new computers. ach new computer wasconnected to one ofsetled eartier. Managers ofschool are anxious about slow finctioning ofthe net and want to know the maximum distance si for which i-thcomputer needs to send signal (i.e. length of cable to the most distant computer). You need to provide this information.

Hint: he example input is coresponding to this graph. And from the graph, you can se that the computer 4 is farthest one from 1, so S1 =3. Computer 4 and 5 are the farthest ones from 2, so S2=2. Computer 5 is the farthest one from3.so S3=3. We also get S4=4,S5-4.

输入格式

Input file contains multiple test cases.in each case there is natural number N (N<=1000) in the first line, folowed by (N-1) lines with descriptions of computers. ithline contains two natural numbers - number of computer.to which i-th computer is conected and leneth ofcable used for connection. "otaleneth of cable doe notexceed 10^9. Numbers in lines ofinput are separated by a space.

输出格式

For each case output N lines. i-th line must contain number Si for i-th computer (1<-i<=N)

5
1 1
2 1
3 1
1 1
3
2
3
4
4