2014多校1(1003)hdu4863
2014-08-02 20:10
99 查看
【BestCoder Round #3 来了!】8月3号19:00~21:00(赛前30分钟停止注册比赛) |
Centroid of a TreeTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 194 Accepted Submission(s): 81 Problem Description Given a tree T with N vertices, your task is calculating the number of the connected sub-tree of T, which has the same centroid as T. In order to define the centroid, some integer value will be associated to every vertex. Let's consider the vertex k. If we remove the vertex k from the tree (along with its adjacent edges), the remaining graph will have only N-1 vertices and may be composed of more than one connected components. Each of these components is (obviously) a tree. The value associated to vertex k is the largest number of vertices contained by some connected component in the remaining graph, after the removal of vertex k. All the vertices for which the associated value is minimum are considered centroids. A graph can have an arbitrary number of centroids. However,it can be proved that for trees, there are only two possibilities: 1. The tree has precisely one centroid. 2. The tree has precisely two centroids. In this case, the two centroids are adjacent. Note that in case 2, we just consider that T has two centroids, you should only count the sub-tree which has the two same centroids as T. Input The first line of the date is an integer T, which is the number of the text cases. Then T cases follow each case starts of a number N descript above. Then N-1 lines follow, each line contains two integers x and y, which means that there is a edge between x and y in tree T, you can assume that the index of T is from 1 to N. 1 <= T <= 50, 1 <= N <= 200, Output For each case, output the case number first, then output the number of the connected sub-tree which has the same centroid as T. Give your answer modulo 10007. Sample Input 5 1 2 1 2 3 1 2 1 3 4 1 2 1 3 1 4 5 1 2 1 3 1 4 4 5 Sample Output Case 1: 1 Case 2: 1 Case 3: 2 Case 4: 5 Case 5: 6 |
重心如果是两个则很简单,直接将两边相同节点的方案数相乘,然后再累加起来就好了
如果只有一个重心,那么可以从反面情况来求解,即先可以算出不满足的方案数,以该重心为根,枚举最大分支,剩下的分支的节点数中和要小于最大分支的节点数,这个直接用背包处理处理即可,最后再用所有情况减去反面的情况就是答案了。
相关文章推荐
- 2014上海网络预选赛1003(树链剖分)HDU5044
- hdu 4962 Closed Paths 计算几何 2014 Multi-University Training Contest 9-1003
- poj 5024&&&2014 ACM/ICPC Asia Regional Guangzhou Online 1003(预处理)
- 2014 百度之星 1003 题解 Xor Sum
- HDU 5044 Tree(LCA ,2014上海网络赛1003)
- hdu 4973 A simple simulation problem 线段树 2014 Multi-University Training Contest 10-1003
- 2014上海全国邀请赛1003(hdu 5092)
- 【HDU】4923 Room and Moor(2014多校第六场1003)
- hdu 4937 2014 Multi-University Training Contest 7 1003
- 2014多校10(1003)hdu4973(简单线段树区间操作)
- 2014广州网络赛1003||hdu 5024 搜索
- 2014百度之星资格赛1003
- 2014西安全国邀请赛 1003 && HDU 4849 Wow! Such City! (单源最短路Djikstra算法)
- 2014多校5(1003)hdu4913(线段树区间操作)
- HDU5044 2014上海网络赛1003 tree
- 2014 多校07 1003 Lucky Number
- HDU 5024 Wang Xifeng's Little Plot(2014广州网络赛1003)
- 2014编程之美初赛第二场1003 集合
- 2014基本贪心1003
- 百度之星2014资格赛 1003 - Xor Sum