题目描述
C++代码
样例
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
const int N = 1e5 + 10;
int n;
double a, b;
struct Node {
vector<int> ne;
bool vis;
}node[N];
double memo[N];
double dfs(int x,double d)
{
if(memo[x]!=0)
{
return memo[x];
}
if (node[x].vis == true)
{
return memo[x]= (d * node[x].ne[0]);
}
else {
double d1 = 0;
for (int i = 0; i < node[x].ne.size(); i++)
{
double p = dfs(node[x].ne[i], (d*(1+0.01*b)));
memo[node[x].ne[i]]=p;
d1+=p;
}
return memo[x]=d1;
}
}
int main()
{
cin >> n >> a >> b;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
if (x == 0)
{
int y;
cin >> y;
node[i].vis = true;
node[i].ne.push_back(y);
}
else {
node[i].vis = false;
while (x--)
{
int y;
cin >> y;
node[i].ne.push_back(y);
}
}
}
cout << fixed << setprecision(1) << dfs(0, a);
return 0;
}