Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- #include <cmath>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <deque>
- #include <ctime>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int ui;
- #define mh() make_heap()
- #define poph() pop_heap()
- #define pushh() push_heap()
- #define sor(n) n.begin(), n.end()
- #define rsor(n) n.rbegin(), n.rend()
- #define mp make_pair
- #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
- #define p(T) pair<T,T>
- #define znac(l) abs(l)/l
- const ll ok = ll(1e9 + 7);
- /*struct top
- {
- vector<top *>next;
- ll nm, t;
- };
- top* nwtp(ll nm, ll t)
- {
- top* ntp = new top();
- ntp->nm = nm;
- ntp->t = t;
- return ntp;
- }
- void addtree(top* cor, ll nm, ll t, ll vas)
- {
- if (cor->nm != vas)
- {
- if (cor->next.size() != 0)
- for (int i = 0; i < cor->next.size(); i++)
- {
- addtree(cor->next[i], nm, t, vas);
- }
- }
- else
- {
- cor->next.push_back(nwtp(nm, t));
- }
- }*/
- vector<p(ll)>tree[10200];
- ll vas[10200];
- double chk(double x, ll v)
- {
- if (tree[v].size() != 0)
- {
- vector<ll>p;
- for (int i = 0; i < tree[v].size(); i++)
- {
- p.push_back(chk(x, tree[v][i].first));
- }
- sort(sor(p));
- double mayb = double(tree[v].size()) / 100.0;
- mayb = mayb*x;
- ll sc = 0;
- if (mayb - int(mayb) >= 1e-9)
- {
- sc = ll(mayb) + 1;
- }
- else
- {
- sc = ll(mayb);
- }
- ll t = -1;
- for (int i = 0; i < sc; i++)
- {
- t = max(t,p[i]);
- }
- t += vas[v];
- return t;
- }
- else
- return vas[v];
- }
- double binpos(ll v, ll t)
- {
- double r = 1000000;
- double l = 0;
- while (r-l>=1)
- {
- double tm = (l + r) / 2;
- double ty = chk(tm / 10000.0, v);
- if (ty > t)
- {
- r = tm;
- }
- else
- {
- l = tm;
- }
- }
- return ll(r);
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- files;
- #endif
- ll n, t;
- cin >> n >> t;
- ll prvas, prt;
- vas[1] = 0;
- for (int i = 2; i <= n; i++)
- {
- cin >> prvas >> prt;
- tree[prvas].push_back({ i,prt });
- vas[i] = prt;
- }
- double x = binpos(1, t);
- x /= 10000.0;
- printf("%.10lf", x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement