1267-network
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_ problem&problem=3708
Consider a tree network with n nodes where the internal nodes correspond to servers and the terminal nodes correspond t o clients. The nodes are numbered from 1 ton. Among the servers, there is a original servers which provides VOD (video on Demand) service. To ensure the "quality of service for" clients, the distance from all client to the "VOD ServerS should not exceed a CER Tain value K. The distance from a node you to a nodev in the "the" of the "is defined" to "the" number of edges on the path fromu tov. If there is a nonempty subsetc of clients such this distance from Eachu-C to-S greater thank, then replicas of The VOD system have to is placed in some servers so this distance from each client to the nearest VOD server (the orig Inal VOD system or its replica) ISK or less.
Given a tree network, a server S which has VOD system, and a positive integerk, find the minimum number of replicas neces Sary So, each of the client is within Distancek to the nearest server which has the original VOD system or its replica.
For example, consider the following tree network.
In the above tree, the set of clients are {1, 6, 7, 8, 9,, and, the set of servers is {2, 3, 4, 5,,, and the Original VOD server is located at node 12.
For k = 2, the quality of service isn't guaranteed with one VOD server at node because the clients in {6, 7, 8, 9, 10 } are away from the VOD server at distance>k. Therefore, we need one or more replicas. When one replica is placed in node 4, the distance from all client to nearest server of {4} is less than or equal to 2. The minimum number of the needed replicas is one for this example.
Input
Your is to read the input from standard input. The input consists of T test cases. The number of test cases (T) is given in the ' the ' input. The ' the ' of each test case contains a Integern (3N1) which is the number of nodes to the tree network. The next line contains two Integerss (1SN) and K (K1) where S is the the VOD server and k are the distance value for ensuring the Quality of service. In the followingn-1 lines, the contains a pair of nodes which and the the tree represent.
Output
Your is to write to standard output. Print exactly one line for each test case. The line should contain an integer this is the minimum number of the needed replicas.
Sample Input
2
2
1 2 2 3 3 4 4 5 5 6 7 5 8 5 4 9
3 2
14
14
3 4
1 2 2 3
3 4
4 5 5 6 7 5 8 5 4 9 3 2 12
12
14 11
Sample Output
1
0