Broadcast Stations
Time limit0.5sMemory limit512 MB
Given a tree, assign non-negative integer powers to vertices so every zero-power vertex lies within reach of some positive-power vertex, minimizing the total power. Report that minimum sum.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Tree, Greedy, DFS
- Solved
- No attempts yet
Problem
The connections between cities form a tree with vertices, and each vertex is one city. The distance between two vertices is the number of edges on the unique path between them. Broadcast stations that send out the same information have to be built in some of the cities. A station of transmission power reaches every city at distance or less from it.
Assign a non-negative integer , called the broadcast power, to every vertex of the vertex set of . The assignment has to satisfy the following condition: every vertex with is within distance of some vertex with . A vertex with is a broadcast station of transmission power , and a vertex with can hear the broadcast of if is within distance of .
Among the assignments that satisfy the condition, find the minimum value of .
Figure A.1 shows two assignments of broadcast powers. In (a) only vertex 6 has broadcast power 4 and every other vertex has 0. Every vertex of broadcast power 0 can then hear vertex 6. In (b) vertices 3 and 9 have broadcast powers 2 and 1. Every vertex of broadcast power 0 can hear vertex 3 or vertex 9, and this assignment makes the sum of the broadcast powers as small as possible.


Figure A.1: two assignments of broadcast powers, (a) above and (b) below.
Input
The first line contains one integer (), the number of vertices of the tree . The vertices are numbered from 1 to . Each of the next lines contains two integers and (), an edge that joins vertex and vertex .
Output
Print one line with one integer, the smallest sum of broadcast powers over all assignments that satisfy the condition.