1090. Highest Price in Supply Chain (25)
#include <cstdio>
#include <vector>
#include <cmath>
int maxheight=-1,find=0;
void dfs(int k,int h,std::vector<std::vector<int>> &v)
{
if(maxheight<h)
{
maxheight=h;
find=0;
}
if(maxheight==h)
++find;
for(auto it=v[k].begin();it!=v[k].end();++it)
dfs(*it,h+1,v);
}
int main()
{
std::vector<std::vector<int>> v(100001);
int n,root;
double price,rate;
scanf("%d %lf %lf",&n,&price,&rate);
rate/=100;
for(int i=0;i<n;++i)
{
int e;
scanf("%d",&e);
if(e==-1)
root=i;
else
v[e].push_back(i);
}
dfs(root,0,v);
printf("%.2f %d",price*pow((1+rate),maxheight),find);
return 0;
}