Bzoj 4726: [Poi2017]sabota?

Source: Internet
Author: User

Description

To a tree, the smallest percentage makes the number of traitors not exceeding K.

Sol

Tree-shaped DP.

At the beginning, I wrote a two-point straight ... Then the t ... Complexity should be quite scientific ... But the constant is big ...

Then saw the approach of the tree DP ...

Code
/************************************************************** problem:4726 User:beiyu language:c++ Result : Accepted time:12456 ms memory:37616 kb****************************************************************/#include & lt;cstdio> #include <vector> #include <iostream>using namespace std; #define DEBUG (a) cout<< #a << "=" <<a<<endlconst int N = 500005; int n,k;vector< int > g[n];int sz[n];d ouble f[n];d ouble ans;    inline int in (int x=0,char Ch=getchar ()) {while (ch> ' 9 ' | | ch< ' 0 ') Ch=getchar (); while (ch>= ' 0 ' && ch<= ' 9 ') x=x*10+ch-' 0 ', Ch=getchar (); return x; } void DFS (int u,int fa) {sz[u]=1;for (int i=0,lim=g[u].size (), v;i<lim;i++) V=g[u][i],dfs (V,u), sz[u]+=sz[v];}    void DP (int u,int fa) {if (sz[u]==1) {F[u]=1.0;return;}    for (int i=0,lim=g[u].size (), v;i<lim;i++) {V=G[U][I],DP (v,u), F[u]=max (F[u],min (F[V), (double) sz[v]/(sz[u]-1))); }if (sz[u]>k) Ans=max (Ans,f[u]);} int main () {n=in (), K=in ();    for (int i=2,u;i<=n;i++) u=in (), G[u].push_back (i);    DFS (1,0);    DP (1,0);    printf ("%.8lf\n", ans); return 0;}

  

Bzoj 4726: [Poi2017]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.