matter
不行以后都换成double类型的数据。。。
2.模板:利用DFS求树的深度。
code
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
const int MAXN = 100010;
vector<int> child[MAXN];
int maxdepth = 0 , num = 0;
void DFS(int root , int depth){
// approach the leaf node
if(child[root].size() == 0){
if(depth > maxdepth){
maxdepth = depth;
num = 1;
}
else if(depth == maxdepth){
num ++;
}
return ;
}
// not the leaf node
for(int i = 0 ; i < child[root].size() ; i ++){
DFS(child[root][i] , depth + 1);
}
}
int main(){
int N , father , root;
double P , R;
//input
scanf("%d %lf %lf" , &N , &P , &R);
for(int i = 0 ; i < N ; i ++){
scanf("%d" , &father);
if(father == -1){
root = i;
}
else{
child[father].push_back(i);
}
}
//DFS the tree
DFS(root , 0);
//output
printf("%.2f %d" , P * pow(1 + R / 100 , maxdepth) , num);
return 0;
}