-
Notifications
You must be signed in to change notification settings - Fork 0
/
1079.cpp
70 lines (55 loc) · 1.34 KB
/
1079.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
67
68
69
70
#include <cstdio>
#include <vector>
const int MAXN = 100000 + 10;
double p = 0, r = 0, ans = 0;
struct Node {
Node *fa;
double sum;
int cnt;
bool isLeave;
std::vector<Node*> ch;
Node() : sum(1), cnt(1), isLeave(false) {
fa = nullptr;
ch.clear();
}
void addChild(Node *ch) {
ch->fa = this;
this->ch.push_back(ch);
}
} nodes[MAXN];
void dfs(Node *root) {
if (!root->fa) root->sum = p;
else root->sum = root->fa->sum * (1 + r / 100);
for (auto x : root->ch) {
dfs(x);
}
}
int main() {
int n;
scanf("%d%lf%lf", &n, &p, &r);
for (int i = 0; i < n; i++) {
int num;
scanf("%d", &num);
if (num == 0) {
scanf("%d", &nodes[i].cnt);
nodes[i].isLeave = true;
} else {
for (int j = 0; j < num; j++) {
int x;
scanf("%d", &x);
nodes[i].addChild(&nodes[x]);
}
}
}
dfs(&nodes[0]);
// for (int i = 0; i < n; i++) {
// printf("%lf ", nodes[i].sum);
// }
// printf("\n");
double ans = 0;
for (int i = 0; i < n; i++) {
if (nodes[i].isLeave) ans += (nodes[i].sum * nodes[i].cnt);
}
printf("%.1lf\n", ans);
return 0;
}