#P1264. [ICPC2017 ASIA Daejeon]Broadcast Stations

[ICPC2017 ASIA Daejeon]Broadcast Stations

题目描述

There is a network of cities where broadcast stations, broadcasting identical information, should be placed onsome cities. Each broadcast station has its own transmission power pp so that it can broadcast to any city within distance pp from it. Here, the distance between two vertices is the number of edges included in the (unique)path between them. In this problem, the network of cities is a tree TT with nn vertices each of which represents acity. For a tree TT with a set VV of nn vertices, we will assign a non-negative integer p(v)p(v), called a broadcast power, to every vertex vv in VV such that every vertex uu with p(u)=0p(u) = 0 is within distance p(v)p(v) from some vertex vv withp(v)>0p(v) > 0. Then we can regard the vertices vv with p(v)>0p(v) > 0 as broadcast stations of transmission powerp(v)p(v), and avertex uu withp(u)=0p(u) = 0 can hear the broadcast of vv, if uu is within distance p(v)p(v) from vv. The goal of the problem is to find an assignment of the broadcast powers p(v)p(v) of vertices vv in VV described above minimizing extstylesumvinVp(v)\ extstyle\\sum_{v\\in V}p(v)

For example, in Figure A.1, two cases of an assignment of broadcast powers to vertices are shown. In the case of Figure A.1 (a), only the vertex 6 has the broadcast power 4 and the other vertices have zero. Then all the vertices with the broadcast power 0 can hear the broadcast of the vertex 6. In the case of Figure A.1 (b), two vertices 3 and 9 have the broadcast powers 2 and 1, respectively. Then all the vertices with the broadcast power 0 can hear the broadcast of either the vertex 3 or 9. This case minimizes the sum of broadcast powers. Figure A.1: Two assignments of broadcast powers

输入格式

Your program is to read from standard input. The first line contains one integer n(1lenle5,000)n(1\\le n\\le 5,000) representing the number of vertices of the input treeTT. The vertices of TT are numbered from 1 to nn.Each of the following n1n-1 lines contains two integers aa and bb (1lea,blen)(1\\le a,b\\le n) representing an edge to connect two vertices aa and bb in TT

输出格式

Your program is to write to standard output. Print exactly one line which contains an integer that is the minimum sum of broadcast powers among all the possible assignments of broadcast powers to the vertices inTTdescribed above. The following shows sample input and output for two test cases

样例

6 
1 2 
3 2 
2 4 
5 4 
6 4 
2
12 
1 2 
2 3 
4 5 
5 3 
3 6 
6 7 
7 8 
8 9 
12 9 
9 11 
10 9
3