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?