Uva 3902 Network】的更多相关文章

题目大意: 在非叶子节点上安装最少的服务器使得,每个叶子节点到服务器的距离不超过k. 贪心+图上的dfs. 先从深度最大的叶子节点开始找.找到父节点后再用这个父节点进行扩充. /* *********************************************** Author :guanjun Created Time :2016/5/10 23:15:38 File Name :7.cpp *********************************************…
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1903 题意 一棵树,根上有VOD站,要求任意叶节点到VOD站的距离不超过k,问最少建新VOD站数. 思路 1. 令vod[i]为节点i到VOD站的最短距离,  注意,这是在以i为根的树上有VOD站的情况下,如果没有,vod[i]就设为非法. 依据树形DP的思路,如果在该…
#include<iostream> #include<cstring> #include<vector> using namespace std; +; int n,s,k; vector<int> tree[maxn],nodes[maxn]; int fa[maxn]; bool covered[maxn]; void dfs(int u,int f,int d) { fa[u]=f; int nc=tree[u].size(); &&…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=251  Network  A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers…
Network Consider a tree network with n <tex2html_verbatim_mark>nodes where the internal nodes correspond to servers and the terminal nodes correspond to clients. The nodes are numbered from 1 to n <tex2html_verbatim_mark>. Among the servers, t…
Consider a tree network with n nodes where the internal nodes correspond to servers and the terminalnodes correspond to clients. The nodes are numbered from 1 to n. Among the servers, there is anoriginal server S which provides VOD (Video On Demand)…
人生第一道图论题啊,有木有 题意: 有一个树状网络,有一个原始服务器s,它的服务范围是k 问至少再放多少台服务范围是k的服务器才能使网络中的每个节点都被覆盖掉 解法: 我们以原始服务器为根将其转化成一个有根树,则深度不超过k的节点都已经被原始服务器覆盖. 我们选择深度最大的节点u然后将它的k级祖先设为服务器,进行一次DFS,将所有距离它不超过k的节点覆盖. 表示: 图的表示在这里面是用邻接表来表示的,如果a.b两个节点相邻,则gr[a]中放入b,gr[b]中放入a 怎样才算转化为有根树了?那就是…
模板题,注意输出 #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <vector> #include <stack> using namespace std; typedef long long LL; ; int head[N],tot,n; struct Edge{ int v,next; }edge[N*…
这个题目关键在于把无根树变成有根树:这个用dfs: 然后用贪心的方法,从最深的那层开始,每次找到节点的上k层,建一个服务器,然后用一个dfs把这个服务器能够覆盖的节点标记: #include<cstdio> #include<cstring> #include<vector> #include<algorithm> #define maxn 1005 using namespace std; vector<int>node[maxn],deep[…
输入数据处理正确其余的就是套强联通的模板了 #include <iostream> #include <cstdlib> #include <cstdio> #include <algorithm> #include <vector> #include <queue> #include <cmath> #include <stack> #include <cstring> using namespa…