daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define MAXN 500069
  4. vector <vector <int> > Graph(MAXN);
  5. int Fath[MAXN];
  6. int Size[MAXN];
  7. double curAns[MAXN];
  8. double Ans;
  9. int n,p,k;
  10.  
  11. inline void scan(int &number)
  12. {
  13.     cin >> number;
  14. }
  15.  
  16. double Analise (int v)
  17. {
  18.     double curVa = 0;
  19.     if (Graph[v].size() == 0) curVa = 1;
  20.     for (auto son:Graph[v])
  21.     {
  22.        curVa = max(curVa, min(Analise(son), double(Size[son])/double(Size[v]-1)));
  23.     }
  24.  
  25.     curAns[v] = curVa;
  26.     return curVa;
  27. }
  28.  
  29. int main()
  30. {
  31.     ios_base::sync_with_stdio(0);
  32.     cin.tie(0);
  33.     cout.tie(0);
  34.     scan(n);
  35.     scan(k);
  36.     Size[0] = 1;
  37.     Fath[0] = -1;
  38.  
  39.     for (int i=1; i!=n; ++i)
  40.     {
  41.         scan(p);
  42.         p--;
  43.         Fath[i] = p;
  44.         Graph[p].push_back(i);
  45.         Size[i] = 1;
  46.     }
  47.  
  48.     int m = n;
  49.     while (m--) Size[Fath[m]] += Size[m];
  50.  
  51.     Analise(0);
  52.  
  53.     Ans = 0;
  54.     for (int i=0; i!=n; ++i) if (Size[i] > k) Ans = max(Ans, curAns[i]);
  55.  
  56.     cout.precision(17);
  57.     cout << fixed << Ans;
  58.  
  59.     return 0;
  60. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top