博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LA 3902 UVA 1267 - Network
阅读量:4357 次
发布时间:2019-06-07

本文共 3534 字,大约阅读时间需要 11 分钟。

1267 - Network

Time limit: 3.000 seconds

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 defined 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 , find 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.

 

\epsfbox{p3902.eps}

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 integer n (3$ \le$n$ \le$1, 000) which is the number of nodes of the tree network. The next line contains two integers s (1$ \le$s$ \le$n) and k (k$ \ge$1) where s is the VOD server and k is the distance value for ensuring the quality of service. In the following n - 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 题目大意:给一树型网络,初始一个点s放置一台服务器,给一个k。先要求放置最少的服务器,使得所有叶子节点距离服务器距离<=k。输出k。 先转换成s为根的树,根据观察即可发现策略:从最深的叶子节点开始考虑,每次放在距离最远的没有覆盖的叶子节点k的节点,每放置一个服务器进行一次dfs。 这里用一个深度表node来保存深度:vector
node[maxn]; node[d] 就是深度为d的叶子节点。
1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 9 using namespace std;10 11 #define SI(a) scanf("%d", &(a))12 #define SS(a) scanf("%s", (a))13 #define SC(a) scanf("%c", &(a));14 #define Max(a, b) (a > b ? a : b)15 #define Min(a, b) (a < b ? a : b)16 17 const int maxn = 1000 + 50;18 19 vector
G[maxn];20 vector
node[maxn];21 int covd[maxn];22 int pa[maxn];23 int n, k;24 25 void dfs(int u, int fa, int d) {26 pa[u] = fa;27 int nc = G[u].size();28 if(nc == 1 && d > k) node[d].push_back(u);29 for(int i=0; i
k; d--) {67 for(int i=0; i

 

 

转载于:https://www.cnblogs.com/zhaosdfa/p/3253778.html

你可能感兴趣的文章
Camera Binning Mode
查看>>
Django模板系统
查看>>
位(Bit)与字节(Byte)
查看>>
关于两次指针(struct型)传参数的问题
查看>>
自己制作Linux镜像,CentOS 6.5 Docker自制CentOS镜像
查看>>
linux配置scp交互传输,Linux间传输文件的几种方法scp、sftp
查看>>
linux安装nginx映射目录,centos8自定义目录安装nginx(教程详解)
查看>>
linux cpu scheduler,A Temporal Partition-Based Linux CPU Scheduler
查看>>
c语言怎么写最小公倍数的函数,C语言 · 最小公倍数
查看>>
c语言中的头文件string.h的作用,C语言常用头文件及库函数——string.h
查看>>
c语言字符-1代表什么,玩儿转C语言:符号和字符(1)
查看>>
知道商洛学院c语言章节答案,C语言程序设计(商洛学院)知到章节答案
查看>>
c语言酒精检测仪程序代码,单片机酒精浓度测试仪,代码,原理图
查看>>
单路电压表c语言编程,单片机数字电压表的设计
查看>>
精通c语言的标准,《精通Unix下C语言编程与项目实践》之七——标准I/O重定向
查看>>
蓝桥杯c语言试题 高职,2011l蓝桥杯c语言高职真题附加答案2.doc
查看>>
c 语言 设计算法 例题,C语言程序设计例题.pdf
查看>>
p4 linux 命令行,《linux就该这么学》学习笔记25期2020-P4
查看>>
android9.0官方下载,安卓9.0系统刷机包 官方正式版
查看>>
android 模块封装,Android开发之针对联系人的封装
查看>>