-
Notifications
You must be signed in to change notification settings - Fork 0
/
1090.cpp
66 lines (52 loc) · 1.24 KB
/
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <cstdio>
#include <vector>
const int MAXN = 100000 + 10;
struct Node {
int id;
std::vector<Node *> ch;
double data;
Node() {
ch.clear();
id = 0;
data = 1;
}
void addChild(Node *x) {
ch.push_back(x);
}
} nodes[MAXN];
void dfs(Node *root, double r) {
if (root->ch.empty()) return;
for (auto &x : root->ch) {
x->data = root->data * (1 + r / 100);
dfs(x, r);
}
}
int main() {
int n;
double p, r;
scanf("%d%lf%lf", &n, &p, &r);
for (int i = 0; i < n; i++) nodes[i].id = i;
Node *root = nullptr;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (x == -1) root = &nodes[i];
else nodes[x].addChild(&nodes[i]);
}
root->data = p;
dfs(root, r);
double ans = 0;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (nodes[i].ch.empty()) {
// printf("%.2lf ", nodes[i].data);
if (nodes[i].data == ans) cnt++;
else if (nodes[i].data > ans) {
ans = nodes[i].data;
cnt = 1;
}
}
}
printf("%.2lf %d\n", ans, cnt);
return 0;
}