-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA1090
47 lines (45 loc) · 761 Bytes
/
A1090
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=100010;
int n,maxDepth,num;
double p,r,ans;
vector<int> child[maxn];
void DFS(int index,int depth){
if(child[index].size()==0){
if(maxDepth<depth){
maxDepth=depth;
num=1;
}
else if(maxDepth==depth){
num++;
}
return;
}
for(int i=0;i<child[index].size();i++){
DFS(child[index][i],depth+1);
}
}
int main(){
int father,root;
scanf("%d%lf%lf",&n,&p,&r);
r/=100;
for(int i=0;i<n;i++){
scanf("%d",&father);
if(father!=-1){
child[father].push_back(i);
}
else{
root=i;
}
}
DFS(root,0);
ans=p*pow(1+r,maxDepth);
printf("%.2f %d",ans,num);
}