AcWing 1580. 供应链最高价格
原题链接
简单
作者:
xxxxuu
,
2021-08-22 17:11:00
,
所有人可见
,
阅读 292
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const int N=100010;
int n;
int max_depth=-1;
double p,r;
int cnt[N];
struct node{
vector<int> child;
}tree[N];
void dfs(int root,int depth){
cnt[depth]++;
max_depth=max(depth,max_depth);
if(tree[root].child.size()==0) return;
for(int i=0;i<tree[root].child.size();i++){
dfs(tree[root].child[i],depth+1);
}
}
int main(){
cin>>n>>p>>r;
r/=100.0;
int root;
for(int i=0;i<n;i++){
int pre;
cin>>pre;
if(pre==-1) root=i;
else{
tree[pre].child.push_back(i);
}
}
dfs(root,0);
printf("%0.2f %d\n",p*pow(1+r,max_depth),cnt[max_depth]);
return 0;
}