#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int n, maxnum, maxdepth = 0, root = 0;
double p, r;
vector<int> v[100001];//存放树
void dfs(int index, int depth){
if (v[index].size() == 0) {
if(maxdepth == depth) maxnum++;
if (maxdepth < depth) {
maxdepth = depth;
maxnum = 1;
}
return;
}
for (int i = 0; i < v[index].size(); i++) {//递归访问结点index的子结点
dfs(v[index][i], depth + 1);
}
}
int main(){
cin >> n >> p >> r;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
if(t == -1) root = i;
else v[t].push_back(i);//i是t的子结点
}
dfs(root, 0);
printf("%.2lf %d\n", p * pow(1 + r/100, maxdepth), maxnum);
return 0;
}
1090. Highest Price in Supply Chain (25) dfs
最新推荐文章于 2020-02-24 14:10:42 发布