-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1090.cpp
51 lines (46 loc) · 987 Bytes
/
1090.cpp
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
48
49
50
51
//
// 1090.cpp
// 算法
//
// Created by 王怡凡 on 2017/3/20.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int maxn = 100010;
vector<int> child[maxn];
double p, r;
int n,maxDepth=-1,num=0;
void DFS(int index, int depth) {
if(child[index].size()==0) {
if(depth>maxDepth){
maxDepth = depth;
num = 1;
} else if(depth == maxDepth) {
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 = r/100;
// printf("p:%lf\n",p);
for(int i=0;i<n;i++) {
scanf("%d",&father);
if(father!=-1) {
child[father].push_back(i);
} else {
root = i;
}
}
DFS(root,0);
printf("%.2lf %d",p*pow(1+r,maxDepth),num);
return 0;
}