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. ...
随机推荐
- WIN10无法识别安卓设备,提示Windows 无法验证此设备所需的驱动程序的数字签名
在设备管理器,显示ANDROID设备是感叹号, 不管更新驱动,还是下载什么手机助手自动安装驱动,均不可解. 从属性中查看提示的是“Windows 无法验证此设备所需的驱动程序的数字签名”, 解决办法: ...
- Web项目改名的带来的404not found问题
为了保留上一次编辑的billsys web项目,把项目复制一份到同一个工作空间后,对原来项目名进行了重命名,如右图: 结果再去访问,一直报404错误 解决思路如下: 其实仔细观察,会在项目部署界面发现 ...
- Java序列化及反序列化
序列化概念: 1.Java序列化与反序列化 Java序列化是指把Java对象转换为字节序列的过程:而Java反序列化是指把字节序列恢复为Java对象的过程. 2.为什么需要序列化与反序列化 我们知道 ...
- WRNavigationBar 使用记录
最近在做一个导航栏透明度渐变的效果,发现 WRNavigationBar库很好用,一开始导入到项目,发现导航tiltle颜色一直是黑色的,无论怎么用系统方法改都改不了.后来发现原来库里面有一个方法可以 ...
- XSS漏洞基础
什么是XSS? XSS全程Cross-site scripting,跨站脚本攻击.恶意攻击者往Web页面里插入html代码,当用户浏览该页之时,嵌入其中Web里面的html代码会被执行,从而达到恶意用 ...
- Python基础教程(018)--官方解释器交互运行
前言: 在交互式运行Python程序 内容 在Python的shell中直接输入Python的代码,可以立即执行结果 交互式运行Python的优缺点 1,缺点--代码不能保存 2,不适合运行太大的程序 ...
- 【HDOJ6582】Path(最短路图,最小割)
题意: n,m<=1e4,c<=1e9 思路: #include<bits/stdc++.h> using namespace std; typedef long long l ...
- 2018-2019 ACM-ICPC Brazil Subregional Programming Contest F. Music Festival
题目:https://codeforces.com/gym/101908/problem/F 题意:给你n个舞台,每个舞台有很多个节目,每个节目有个开始时间,结束时间,价值,每个舞台至少出演过一个节目 ...
- window 2008/2012计划任务配置
很多人在问我: 1.Windows Server 2008 计划任务在哪里配置? 2.Windows Server 2008 可以配置每分钟或是每小时执行我的任务吗? 答案是:可以! 首先Window ...
- 五. jenkins部署springboot项目(2)--windows环境--服务
前提:jenkins和springboot运行在同一台机器 springboot 通过winsw部署为服务 winsw 下载地址:https://github.com/kohsuke/winsw/re ...