# [Miscellaneous Questions] URAL1822. Hugo II ' s War

Source: Internet
Author: User

Read Test instructions Please skip the next lump! I have express obstacles!

==========================================

Test instructions: (test instructions really difficult to understand AH!!! Go to his mother's * *)

There is a kingdom, there is a king in the kingdom (numbered 1), he has (numbered 2~n) n-1 a courtiers (these courtiers are not all directly related to him )

And then the king was going to fight, but only if he was ready to fight with the X-percent and more of his immediate subordinates (the one with whom he had a direct relationship).

His direct subordinate also has subordinates, also wants to be in the X percent and above the subordinate to be ready to fight, those direct subordinate will begin to prepare the fight ... Until the last level of subordinates (that is, those who have no subordinates) they are going to start a fight directly.

Of course (except for the king) all the courtiers need time to fight. ti;

There is an upper limit of time t the courtiers prepare the total time cannot exceed t

Give is n (including King Garson), T

Next is the information of the courtiers who numbered 2~n (number 1th is the King) pi and Ti

Pi means that the courtiers are subordinate to the person with the number pi.

TI stands for the time required for the courtiers to fight.

The question is: in the case of no more than T, prepare the battle of the courtiers as much as possible, to find the maximum value of X

Whether to see such a big lump or not know what to say ...

So let's look at a case:

`6 31 22 22 11 21 4N=6 t=3 is a king. 5 courtiers are ready to fight in 3 units of time.Then`
`2nd No.: 1 23rd No.: 2 24th No.: 2 15th No.: 1 26th No.: 1 4Their diagram is this:`

3, 4, 5, 6 of these people have no subordinates, so you can start getting ready to fight right now.

If x is 100, then you need more than 100% subordinates to complete the preparation, that is, 3, 4 to complete 2 to start, when 2, 5, 6 to complete 1 to fight

(3, 4, 5, 6 at the same time to start preparation, 3, 4 are completed 2 days, that is, the third day 2 can begin to prepare (at this time 5 is completed), and then 4 days 2, 5, 6 are completed, 1 can go to fight, so x==100 when a total of 4 days)

If X is 50, then it is necessary for more than 50% subordinates to complete the preparation, that is, when 3 or 4 completes 2 to start; 2, 5, 6, 2 (ceil (3/2) =2) finish 1 to fight.

(3, 4, 5, 6 at the same time began to prepare, the first day of completion of 4 completed, at this time has been satisfied with the "2nd and above the subordinates completed", so 50% began to prepare, the 2nd day end, 2 is ready to complete, at this time 2 has been completed, so that the "5 of the 1th and above subordinates to complete 2 days in total for ==50)

The upper limit of the topic t==3 that must be completed within 3 days of the preparation is clearly x==100 need 4 days not satisfied, and x==50 time needs 2 days, meet.

=================================================

Well, it's the end of the story.

Okay, so how do we do that?

We think first, if we know the X (Percent), and then to determine that can not meet the "preparation days <= upper limit days T" condition is not a lot of simple, as long as the silly add to the Good O (^▽^) o

Okay, so we're going to enumerate each percentage can not meet the conditions and then find the biggest!

The floating-point error is 1e-4 then 0 to 100 for a total of 1e6 cases, then each case must be judged, the worst to add 1e4 times (n Upper 1e4)

So that's O (1e4*1e6), Time limit:500ms

Oh, not enough. (￣▽￣)

That's two cents ~ ~ the upper and lower limits are 0 and 100 respectively, the end of the condition is fabs (l-r) <1e4 ~ ~

And then it's over ...

Then I turn to WA * * * *

The pit daddy's going to be ll

Time limit T obviously only 1e6,ti clearly only 100,1e4 100 plus up also only 1e6! Why are you ll!?

That's right!! Writing so big is to spit groove a ll Ah!

`1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 Const Doubleeps=1e-4;5 6Vector<ll> son[10005], tmp, tot;7 inta[10005];8LL sum[10005];9 Ten intMain () One { A     intN, t; -scanf"%d%d", &n, &t); -      for(intI=2; i<=n;i++) the     { -         intx; -scanf"%d%d",&x,&a[i]); - Son[x].push_back (i); +     } -a[1]=0; +     DoubleL=0, r= -, ans; A      while(Fabs (L-r) >=EPS) at     { -         DoubleM= (L+R)/2.0; -memset (SUM,-1,sizeof(sum)); - tmp.clear (); -Tmp.push_back (1); -          while(!tmp.empty ()) in         { -             intP=tmp[tmp.size ()-1]; to             if(!son[p].size ()) +sum[p]=A[p], Tmp.pop_back (); -             Else the             { *                 if(sum[son[p][0]]==-1) \$                 {Panax Notoginseng                      for(intI=0; I<son[p].size (); i++) - Tmp.push_back (Son[p][i]); the                     Continue; +                 } A tot.clear (); the                  for(intI=0; I<son[p].size (); i++) + Tot.push_back (Sum[son[p][i]); - sort (Tot.begin (), Tot.end ()); \$                 intpp; \$                  for(intI=0; I<son[p].size (); i++) -                     if((i+1)*100.0/son[p].size () >=m) -                     { thepp=i; -                          Break;Wuyi                     } thesum[p]=tot[pp]+(LL) a[p]; - Tmp.pop_back (); Wu             } -         } About         if(sum[1]<=t) \$Ans=m, l=m; -         Else -R=m; -     } Aprintf"%.7lf\n", ans); +     return 0; the}`
URAL 1822

[Miscellaneous Questions] URAL1822. Hugo II ' s War

Related Keywords:

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.