UVa 1267 Network:DFS&贪心

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 to clients. The nodes are numbered from 1 ton . Among the servers, there is an original serverS which provides VOD (Video On Demand) service. To ensure the quality of service for the clients, the distance from each client to the VOD serverS should not exceed a certain value k . The distance from a node u to a nodev in the tree is defined to be the number of edges on the path fromu tov . If there is a nonempty subsetC of clients such that the distance from eachu in C to S is greater thank , then replicas of the VOD system have to be placed in some servers so that the distance from each client to the nearest VOD server (the original 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 necessary so that each client is within distancek from 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 is {1, 6, 7, 8, 9, 10, 11, 13}, the set of servers is {2, 3, 4, 5, 12, 14}, and the original VOD server is located at node 12.

For k = 2 , the quality of service is not guaranteed with one VOD server at node 12 because the clients in {6, 7, 8, 9, 10} are away from VOD server at distance>k . Therefore, we need one or more replicas. When one replica is placed at node 4, the distance from each client to the nearest server of {12, 4} is less than or equal to 2. The minimum number of the needed replicas is one for this example.

Input

Your program 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 first line of the input. The first line of each test case contains an integern(3n1, 000) which is the number of nodes of the tree network. The next line contains two integerss(1sn) and k(k1) where s is the VOD server and k is the distance value for ensuring the quality of service. In the followingn - 1 lines, each line contains a pair of nodes which represent an edge of the tree network.

Output

Your program is to write to standard output. Print exactly one line for each test case. The line should contain an integer that is the minimum number of the needed replicas.

Sample Input

2 14
12 2 

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

Sample Output

1
0

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索at&t汇编语言
, server
, 贪心
, number
, from
, is
, replica placement
, of
, Server12.2.1.2
, The
replica
1267委员会、1267委员会列名问题、1267委员会的列名申请、联合国1267委员会、安理会1267委员会,以便于您获取更多的相关知识。

时间: 2024-09-30 22:50:42

UVa 1267 Network:DFS&贪心的相关文章

uva 1267 Network

点击打开链接uva 1267 思路:先把无根树转化为有根树然后找深度最大的点进行dfs 分析: 1 首先我们应该先把这个无根树转化为有根树,然后我们就可以知道每一个叶子节点相对与根节点的距离 2 接下来我们考虑一下深度最大的节点,假设当前的节点u是深度最大的节点,那么我们可以知道u的k级祖先(父亲是1级,父亲的父亲是2级)处放置服务器肯定比1-k-1任何的一级都优. 3 那么我们每放一个服务器进行一次的dfs,把那些和当前服务器距离小于等于k的节点全部覆盖.注意本题只需要覆盖叶子,而不需要覆盖中

UVa 10020 Minimal coverage:贪心&区间覆盖

10020 - Minimal coverage Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=961 The Problem Given several segments of line (int the X axis) with coordinates

UVa 10718 Bit Mask:贪心&位运算

10718 - Bit Mask Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1659 In bit-wise expression, mask is a common term. You can get a certain bit-pattern using mask. For exa

UVa 12261 High Score:贪心&“向左走,向右走”

12261 - High Score Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&category=244&page=show_problem&problem=3413 思路:注意名字中有若干个A的情况,这时对每串连续的A进行"向左走,向右走"的判断,取所有情况中的最小值输出即可. 完整代码: /*0.0

UVa 10004 Bicoloring (DFS&二分图)

10004 - Bicoloring Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=945 In 1976 the ``Four Color Map Theorem" was proven with the assistance of a comp

uva 11300 - Spreading the Wealth

点击打开链接uva 11300 思路:数学分析+贪心 分析: 1 首先最终每个人的金币数量可以计算出来,它等于金币总数除以人数n.接下来我们用m来表示每人的最终的金币数 2 现在假设编号为i的人初始化为Ai枚金币,Xi表示第i个人给第i-1个人Xi枚金币,对于第一个人来说他是给第n个人. 3 根据第二点可以知道                                                                                              

UVa 10369:Arctic Network(求最小生成树的第k小边)

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1310 题目: Problem C: Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts by a wir

UVa 10603:Fill,经典倒水问题+隐式图搜索+dfs

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=110&page=show_problem&problem=1544 类型: 隐式图搜索 原题: There are three jugs with a volume of a, b and c liters. (a, b, and c are positive integers not greater th

CERC 2004 / UVa 1335 Beijing Guards:二分&贪心&想法题

1335 - Beijing Guards Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_problem&problem=4081 Beijing was once surrounded by four rings of city walls: the Forbidden City Wa