当前位置: 首页 > news >正文

新乡百度网站优化排名余姚关键词优化公司

新乡百度网站优化排名,余姚关键词优化公司,园区网站到底怎么建设,企业软文怎么写题意#xff1a;有n个谷仓有n-1条路连接#xff0c;问最少删除哪几个点才能使得删除点后得到的连通图的加点数不大于n/2. 分析#xff1a;求树的重心的变形题#xff0c;poj3107的简单版#xff0c;一遍dfs从叶子到根转移找出找到以每个节点为根的子树的结点数#xff0…题意有n个谷仓有n-1条路连接问最少删除哪几个点才能使得删除点后得到的连通图的加点数不大于n/2. 分析求树的重心的变形题poj3107的简单版一遍dfs从叶子到根转移找出找到以每个节点为根的子树的结点数f[u]{ f[v1]f[v2].....f[vn] }1;使得每棵子树节点数小于n/2并且父节点得那个连通图节点数小于等于n/2即n-f[u]n/2. 如果没有这样的点输出NONE Time limit     1000 ms Memory limit     65536 kB OS     Linux Source      USACO 2004 December Silver After Farmer John realized that Bessie had installed a tree-shaped network among his N (1 N 10,000) barns at an incredible cost, he sued Bessie to mitigate his losses.  Bessie, feeling vindictive, decided to sabotage Farmer Johns network by cutting power to one of the barns (thereby disrupting all the connections involving that barn). When Bessie does this, it breaks the network into smaller pieces, each of which retains full connectivity within itself. In order to be as disruptive as possible, Bessie wants to make sure that each of these pieces connects together no more than half the barns on FJ.  Please help Bessie determine all of the barns that would be suitable to disconnect. Input * Line 1: A single integer, N. The barns are numbered 1..N.  * Lines 2..N: Each line contains two integers X and Y and represents a connection between barns X and Y. Output * Lines 1..?: Each line contains a single integer, the number (from 1..N) of a barn whose removal splits the network into pieces each having at most half the original number of barns. Output the barns in increasing numerical order. If there are no suitable barns, the output should be a single line containing the word NONE. Sample Input 10 1 2 2 3 3 4 4 5 6 7 7 8 8 9 9 10 3 8 Sample Output 3 8 Hint INPUT DETAILS:  The set of connections in the input describes a tree: it connects all the barns together and contains no cycles.  OUTPUT DETAILS:  If barn 3 or barn 8 is removed, then the remaining network will have one piece consisting of 5 barns and two pieces containing 2 barns. If any other barn is removed then at least one of the remaining pieces has size at least 6 (which is more than half of the original number of barns, 5). 题意 给定一棵无向树节点为nn10000问删除那些节点可以使得新图中的每一个连通分支的节点数都不超过小于n/2 思路 树形dp任意定跟求出每个节点的儿子节点每个点为根的子树的节点数dp[i]然后考察每一个点如果n-dp[i]n/2以及以i的每一个儿子为根的子树的节点数都dp[u]n/2那么这个点就满足条件 /*题意给了一棵节点数为n的树的对应关系让判断去掉哪些 节点能使子数的大小小于等于n/2并将符合条件的节点从小到 大输出如果没有符合条件的节点则输出 “NONE”。 思路既然是让求哪些ji节点符合条件可以用邻接表构建一个 图然后用dfs找出每一个节点下连的图的dax大小些节点符合 条件将节点存入ans数组中。*/ #includecstdio #includecstring #includealgorithm #define N 10010 using namespace std; int n,s,e,first[N],book[N],ans[N]; struct node {int x,y; }que[2*N]; void add(int x,int y) //构建邻接表的函数 {que[e].xx;que[e].yfirst[y];first[y]e; } int dfs(int x) {int num0,sum0;book[x]1;int kfirst[x],flag0;while(k!-1){if(!book[que[k].x]){numdfs(que[k].x);sumnum;if(numn/2) //x节点下的图的大小超过了n/2不符合条件flag1;}kque[k].y;}if(n-sum-1n/2) //另一半是否小于等于n/2flag1;if(!flag)ans[s]x;return sum1; //加上自己 } int main() {while(~scanf(%d,n)){memset(first,-1,sizeof(first));//初始化memset(book,0,sizeof(book));se0; //有s个节点符合条件e用邻接表表示无向图的大小int a,b;for(int i1;in;i){scanf(%d%d,a,b);add(a,b); //构建邻接表add(b,a); //无向图}adfs(1); //从第一个点开始尝试if(s) //有s个节点符合条件{sort(ans,anss); //从小到大排序输出for(int i0;is;i)printf(%d\n,ans[i]);}else //没有符合条件的节点printf(NONE\n);} }
http://www.pierceye.com/news/605674/

相关文章:

  • 娄底网站制作备案号查询平台
  • 青岛网站排名方案优化的定义
  • 微网站开发外包杨浦做网站公司
  • 网站推广服务包括哪些个人简历网官网免费
  • 铜仁住房和城乡建设局网站安贞做网站公司
  • 做网站客户尾款老不给怎么办东莞市研发网站建设品牌
  • 文化网站策划wordpress iscategory
  • 北京社区网站建设wordpress主题 sen
  • 做外贸商城网站重庆seo整站优化方案范文
  • 做AI免费网站wordpress 论坛app
  • 东阿网站建设产品芜湖网络科技有限公司
  • 提供网站技术北京中小企业公司名单
  • 专业的建站公司都具备什么条件凡科建站收费价目表
  • 修改网站主目录的位置wordpress商品展示模板
  • 微信微网站是什么案例天津室内设计培训
  • 如何做网站网页广州海珠网站开发设计
  • 做技术网站赚钱集团网站建设新闻
  • 建立门户网站的意义自己搞个网站需要多少钱
  • 佛山网站优化好华为邮箱注册
  • 哈尔滨网站建设公司名字如何做网络营销推广员
  • 做详情页到那个网站找模特素材怎么黑进网站后台
  • 郑州seo建站深圳专业软件网站建设
  • 廊坊网站搜索优化互联网站账户e服务平台
  • 昆明建设网站wordpress设置中改网站
  • 无锡专业网站制作的公司移动互联网开发技术有哪些
  • 济南市城市建设集团网站wordpress user role editor
  • linux 配置网站域名做资金盘 互助盘的网站
  • 网站开发工程师培训定制网站开发app费用
  • 给菠菜网站做外包免费做思维导图的网站
  • 网站建设服务哪家好如何做属于自己的网站