UVALive 3902 Network (树+dfs)
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 to n. Among the servers, there is an
original server S which provides VOD (Video On Demand) service. To ensure the quality of service for
the clients, the distance from each client to the VOD server S should not exceed a certain value k. The
distance from a node u to a node v in the tree is dened to be the number of edges on the path from u
to v. If there is a nonempty subset C of clients such that the distance from each u in C to S is greater
than k , 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) is k or less.
Given a tree network, a server S which has VOD system, and a positive integer k, nd the minimum
number of replicas necessary so that each client is within distance k 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 f1, 6, 7, 8, 9, 10, 11, 13g, the set of servers is f2, 3, 4, 5, 12,
14g, 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 f6, 7, 8, 9, 10g 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
f12, 4g 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 rst line of the input. The rst line of each test case contains an integer
n (3 n 1; 000) which is the number of nodes of the tree network. The next line contains two
integers s (1 s n) and k (k 1) where s is the VOD server and k is the distance value for ensuring
the quality of service. In the following n
UVALive 3902 Network (树+dfs)的更多相关文章
- [UVALive 3902] Network
图片加载可能有点慢,请跳过题面先看题解,谢谢 一道简单的贪心题,而且根节点已经给你了(\(S\)),这就很好做了. 显然,深度小于等于 \(k\) 的都不用管了(\(S\) 深度为0),那么我们只需要 ...
- UVaLive 3902 Network (无根树转有根树,贪心)
题意:一个树形网络,叶子是客户端,其他的是服务器.现在只有一台服务器提供服务,使得不超k的客户端流畅,但是其他的就不行了, 现在要在其他结点上安装服务器,使得所有的客户端都能流畅,问最少要几台. 析: ...
- UVALive3902 Network[贪心 DFS&&BFS]
UVALive - 3902 Network Consider a tree network with n nodes where the internal nodes correspond to s ...
- HDU 5692 线段树+dfs序
Snacks Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- Tsinsen A1505. 树(张闻涛) 倍增LCA,可持久化线段树,DFS序
题目:http://www.tsinsen.com/A1505 A1505. 树(张闻涛) 时间限制:1.0s 内存限制:512.0MB 总提交次数:196 AC次数:65 平均分: ...
- 51 nod 1681 公共祖先 (主席树+dfs序)
1681 公共祖先 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 有一个庞大的家族,共n人.已知这n个人的祖辈关系正好形成树形结构(即父亲向儿子连边). 在另 ...
- BZOJ_3252_攻略_线段树+dfs序
BZOJ_3252_攻略_线段树+dfs序 Description 题目简述:树版[k取方格数] 众所周知,桂木桂马是攻略之神,开启攻略之神模式后,他可以同时攻略k部游戏.今天他得到了一款新游戏< ...
- 【XSY2534】【BZOJ4817】树点涂色 LCT 倍增 线段树 dfs序
题目大意 Bob有一棵\(n\)个点的有根树,其中\(1\)号点是根节点.Bob在每个点上涂了颜色,并且每个点上的颜色不同.定义一条路径的权值是:这条路径上的点(包括起点和终点)共有多少种不同的颜 ...
- 【BZOJ】3991: [SDOI2015]寻宝游戏 虚树+DFS序+set
[题意]给定n个点的带边权树,对于树上存在的若干特殊点,要求任选一个点开始将所有特殊点走遍后返回.现在初始没有特殊点,m次操作每次增加或减少一个特殊点,求每次操作后的总代价.n,m<=10^5. ...
随机推荐
- 天池平台再升级,打造产业AI知识共享、技术共享平台
在5月23日的云栖大会·武汉峰会上,天池发布“全球AI开发者计划”,打造一站式人工智能知识共享平台,计划2年内在平台上集聚30万AI工程师.同时,阿里云天池正式升级,成为从产业机会到实施交付一站式解决 ...
- 4412 GPIO读 和 ioremap控制GPIO寄存器
一.配置GPIO读 在视频14的基础上做 1.利用拨码开关来实现GPIO输入 所以AP_SLEEP对应GPC0_3,然后在drivers/gpio/gpio-exynos4.c中对应EXYNOS4_G ...
- java 随机读写访问流及seek方法
package stream; import java.io.File; import java.io.FileNotFoundException; import java.io.IOExceptio ...
- 基于Socket和OpenCV的实时视频传输
https://blog.csdn.net/pengz0807/article/details/52204475
- codeforces 111B/112D Petya and Divisors
题目:Petya and Divisors传送门: http://codeforces.com/problemset/problem/111/B http://codeforces.com/probl ...
- php中class类文件引入方法汇总
在项目中 总是会用到类文件引入的操作,在此简单总结下: 方法一: 使用 include,require,include_once,require_once. 其中:*_once once意为曾经 ...
- appium定位学习
前面也介绍过appium的一些定位方法,今天看到一篇博客,里面的方法总结的,就转载过来. 本文转自:https://www.cnblogs.com/Mushishi_xu/p/7685966.html ...
- 【SpingBoot】 测试如何使用SpringBoot搭建一个简单后台1
很久没写博客了,最近接到一个组内的测试开发任务是做一个使用SpringBoot 开发一个后台程序(还未完成),特写感想记录一下 1. 为什么选择SpringBoot ? 首先是目前很多公司的后台还是J ...
- 在windows下用脚手架搭建vue环境
做了几个月vue项目,最近两个项目使用脚手架搭建的,确实用脚手架搭建方便了许多,想想以前自己手配的时候,确实是... 1.在这之前我是默认你已经使用过vue的,也默认你已经安装了node.js 2.接 ...
- xshell的安装及连接linux的使用方法
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/lx_Frolf/article/deta ...