代码如下:
#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE=100010;
int n;
double p,r;
int hashtable[MAX_SIZE]={0};
struct node
{
vector<int> child;
double price;
int high;
}Node[MAX_SIZE];
void DFS(int index,int high)
{
hashtable[high]++;
Node[index].high=high;
Node[index].price=p*pow((1+r),Node[index].high);
for(unsigned int i=0;i<Node[index].child.size();i++)
{
DFS(Node[index].child[i],high+1);
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin>>n>>p>>r;
r=r/100;
int root=-1;
for(int i=0;i<n;i++)
{
int tmp;
cin>>tmp;
Node[tmp].child.push_back(i);
if(tmp==-1)
root=i;
}
DFS(root,0);
double max_p=-1;
int res=-1;
for(int i=0;i<n;i++)
{
if(Node[i].price>max_p)
{
max_p=Node[i].price;
res=hashtable[Node[i].high];
}
}
cout<<setiosflags(ios::fixed)<<setprecision(2)<<max_p<<" "<<res;
return 0;
}