与1079类似
数据大,用bfs
#include <cstdio>
#include <math.h>
#include <vector>
#include <queue>
using namespace std;
#define MAX 100010
struct no{
int layer;
vector <int> next;
}node[MAX];
int n;
double p,r;
int root;
void bfs(double &ans,int &cnt){
queue <int> q;
node[root].layer=0;
q.push(root);
while(!q.empty()){
int now=q.front();
q.pop();
int lay=node[now].layer;
if(node[now].next.size()==0){
double tmp=p*pow(r,lay);
if(tmp==ans){
cnt++;
}else if(tmp>ans){
ans=tmp;
cnt=1;
}
}else{
for(int i=0;i<node[now].next.size();i++){
int k=node[now].next[i];
node[k].layer=lay+1;
q.push(k);
}
}
}
}
int main(){
freopen("in.txt","r",stdin);
scanf("%d %lf %lf",&n,&p,&r);
r=1+r*0.01;
for(int i=0;i<n;i++){
int x;
scanf("%d",&x);
if(x==-1){
root=i;
}else{
node[x].next.push_back(i);
}
}
int cnt=0;
double ans=0;
bfs(ans,cnt);
printf("%.2lf %d\n",ans,cnt);
return 0;
}