Sum distance

0

0 votes
Problem

 

Again Saitama is bored!! And this time he decides that he will  play a game. Given is a tree of nodes. For every node (1in) he wants to find out the sum of distances of all the other nodes from the i-th node. Since he is not very good in solving tree-related problems, he has asked you to do it instead. Can you solve the problem.

Input format

  • First line contains single integer n.
  • next n-1 lines contain two integers and y.

Output format

  • Print n integers, the i-th integer is the sum of distances of all other nodes from i-th node.

Constraints

  • 1n2104
  • 1x,yn
Time Limit: 1
Memory Limit: 512
Source Limit:
Editor Image

?