-
Notifications
You must be signed in to change notification settings - Fork 0
/
1079.cpp
49 lines (49 loc) · 1.04 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
//
// main.cpp
// test
//
// Created by 李寻欢 on 2019/9/26.
// Copyright © 2019 李寻欢. All rights reserved.
//
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <unordered_map>
#include <string.h>
using namespace std;
int n,k,son,w;
double p,r;
double ans = 0;
unordered_map<int, vector<int>> graph;
unordered_map<int, int> weight;
void dfs(int root,int depth){
if (graph.find(root) == graph.end()) { //找到叶子结点就算钱
ans += p*pow(1+r, depth)*weight[root];
return;
}
for(auto it:graph[root]) dfs(it, depth+1);
}
int main(){
scanf("%d%lf%lf",&n,&p,&r);
r /= 100;
for(int i=0;i<n;++i){
scanf("%d",&k);
if(k){
for(int j=0;j<k;++j){
scanf("%d",&son);
graph[i].push_back(son);
}
}else{
scanf("%d",&w);
weight[i] = w;
}
}
dfs(0, 0);
printf("%.1f",ans);
}