Dichotomy method Organ Saltless

Source: Internet
Author: User



现在某组织中(记作R)有n个人,他们的联络网形成一棵以Saltless为根的树,有边相连代表两人可以直接联络。 每个人有一个代号,Saltless代号为1,且除Saltless外每个人的父节点的代号小于他自己的代号。 由于某些原因,Saltless给R的成员分别下达紧急任务,R需要分成m组行动,每个组必须满足如下条件:      1、每个组员仅分在本组中      2、至少有一个组员      3、任意两个组员无需通过本组外的人就可以联络(但可以通过本组组员进行联络) 每个人有一个能力指数,一个组的能力指数是全组人能力指数之和。 对于任意一种正确的分组,平均度就是m组中最小能力指数。为了分组较为平均,Saltless希望平均度尽可能大。 【格式】 PROGRAM NAME: organ INPUT FORMAT: 第一行为三个数:n,m,和Saltless的能力指数(1<=m<=n<=10000)。 接下来n-1行,每行两个数:此人的父节点代号和他的能力指数(能力指数值为正整数,不超过30,行数就是他本身的代号) OUTPUT FORMAT: 输出格式: 一个数,表示最大的平均度。 SAMPLE INPUT (organ. in ) 7 2 2 1 4 1 5 2 1 2 2 3 4 4 3 SAMPLE OUTPUT (organ. out ) 10 【Hint】 分组:{1,3,6},{2,4,5,7}

1 /*The key to this problem is that the child node number must be less than its father number, then we can reverse the loop to the topic (from the child to the parent) to traverse all points. 2 a minimum value of two, if I this node of the subtree (must be interconnected) the sum of less than x, then add these values to the father of I, else on the number of groups +1,3 Test if the last number of groups more than equal to M, is the minimum value of small, l=mid+1,else r=mid+1, seemingly the final output L or R, because the topic and different, I do not distinguish, are used sample test4 */5 #defineN 100116#include <iostream>7 using namespacestd;8#include <cstdio>9#include <cstring>Ten intP[n],fa[n],abi[n],n,m,l=0, r=0; OneInlinevoidinput () A { -scanf"%d%d%d", &n,&m,&abi[1]); -      for(intI=2; i<=n;++i) the     { -scanf"%d%d",&fa[i],&abi[i]); -r+=Abi[i]; -     } + } - BOOLCheckintx) + { A      for(intI=1; i<=n;++i) atp[i]=Abi[i]; -     intnum=0; -      for(inti=n;i>=1;--i) -       if(p[i]<x) p[fa[i]]+=P[i]; -       Elsenum++; -     return(NUM&GT;=M);/*when the number is just taken, we also need to take the big, because the problem to the minimum value of the largest*/ in } - intMain () to { + input (); -     intmid; the      while(l<=R) *     { $Mid= (l+r) >>1;Panax Notoginseng         if(check (mid)) -L=mid+1; the         Elser=mid-1; +     } Aprintf"%d\n", R); the     return 0; +}

Dichotomy method Organ Saltless

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.