实际是求叶节点的最大深度和统计位于最大深度处的叶节点个数
可结合A1079题
#include <iostream>
#include <vector>
#include <math.h>
#define maxn 100000
using namespace std;
struct node{
vector<int>children;
}t[maxn];
int n;
double price,rate;
int count=0;
int deepest=0;
void dfs(int root,int depth){
if(t[root].children.size()==0){
if(depth==deepest){
count++;
}
else if(depth>deepest){
count=1;
deepest=depth;
}
return ;
}
for (int i = 0; i < t[root].children.size(); ++i) {
dfs(t[root].children[i],depth+1);
}
}
int main(){
cin>>n>>price>>rate;
int root;
rate/=100.0;
for (int i = 0; i < n; ++i) {
int parent;
cin>>parent;
if(parent==-1){
root=i;
continue;
}
t[parent].children.push_back(i);
}
dfs(root,0);
printf("%.2f %d\n",price*pow(1+rate,deepest),count);
return 0;
}