Bus Routes
InterviewTime limit3sMemory limit1024 MB
On a tree with N stops, every ordered pair sends a bus along the unique path; for each stop count how many of the N(N-1) buses halt there, including endpoints.
Problem
A Czech town called Kocourkov has a public transport system. It has bus stops and two-way roads, and each road joins two different stops. From any stop you reach every other stop by following roads.
Every morning each stop sends out exactly one bus to every other stop, so there are buses in total. A bus halts once at every stop on the route from its origin to its destination.
Every stop needs a timetable that lists all the buses halting there. The buses that begin their route at that stop and the buses that end their route there belong on the timetable too.
You are given a description of the transport system in Kocourkov. For every stop, count the buses that halt there.
Input
The first line contains , the number of bus stops. The stops are numbered 1 through . Each of the next lines describes one road of the town and contains the numbers of the two different stops it joins, and ().
.
Output
Print lines. Line contains a single integer, the number of buses that halt at stop .