[bzoj4726] Sabota

Source: Internet
Author: User

Do the problem too little, everything to see the puzzle.

Test instructions only give a traitor, then he must be the leaf node (worst case), then the "lead rebel" point must constitute a chain.

F[u] means that u do not take the lead in the smallest of rebellions, then consider each of its sons V, (not rebel) F[v], (Rebellion) size[v]/(size[u]-1), here take a min.

Because it is the worst case, I take Max for all my sons.

Now consider how the answer is structured (this I've been thinking about for a long time), for STD Ans=max (ans,f[u]) (size[u]>k),

The necessity of pre-certification: Obviously, each tree size greater than k, we can not fill, ans at least to reach F[u].

Re-sufficiency: we just asked each subtree of size greater than K. Perhaps the choice in their f[u] is illegal, but it does not affect the answer; Moreover, the subtree that first reached K must not lead the rebellion, so it does not need to be transferred again. So strictly speaking of a certain question of the STD also less a word "has been marked", just do not know why can. (Maybe not to write is right, involved in a bunch of inequalities, I can't testify anyway)

#include <cstdio>#include<algorithm>#defineEPS 1e-8#defineN 1000010using namespacestd;intedgenum,n,k;intVet[n],head[n],size[n],son[n],next[n];DoubleF[n];Doubleans=0;voidAddintUintv) {Edgenum++;vet[edgenum]=v;next[edgenum]=head[u];head[u]=Edgenum;}voidDfsintu) {    inte=head[u];size[u]=1; son[u]=0;  while(e>0){        intv=Vet[e];        DFS (v); Son[u]+=size[v];size[u]+=Size[v]; E=Next[e]; } e=head[u];if(e==0) {F[u]=1.0; if(size[u]>k) ans=Max (Ans,f[u]); return; }     while(e>0){        intv=Vet[e]; if(size[v]>k) {E=next[e];Continue;}///////////that ' s it!F[u]=max (F[u],min (F[V),1.0*size[v]/(size[u]-1))); E=Next[e]; }    if(size[u]>j) {ans=Max (Ans,f[u]); }}intMain () {scanf ("%d%d",&n,&K);  for(intI=2; i<=n;i++){        intX;SCANF ("%d",&x);    Add (x,i); } DFS (1); printf ("%.10LF", ans);}
bzoj4726

[bzoj4726] Sabota

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.