this solution shows well in time and space complexity,but it exceeds limited time at last case.
even change cin to scanf.maybe there are some leaves that far away from the root.
#include<iostream>
#include<cmath>
using namespace std;
struct _leaf
{
int amount;
int index;
};
int main()
{
// freopen("C:\\Users\\Frank Wang\\Desktop\\in.txt","r",stdin);
const int N=100001;
int n,ii=0;
_leaf leaf[N];
int parent[N];
double p,r,pr;
scanf("%d%lf%lf",&n,&p,&r);
pr=1+r/100;
for(int i=0;i<n;i++)
{
int k;
scanf("%d",&k);
if(k==0)
{
scanf("%d",&leaf[ii].amount);
leaf[ii].index=i;
++ii;
}
else
{
for(int j=0;j<k;j++)
{
int x;
scanf("%d",&x);
parent[x]=i;
}
}
}
//compute the level of leaf
//compute sales from all retailers
double ans=0;
for(int i=0;i<ii;i++)
{
int tmp=leaf[i].index;
double pr_tmp=1;
while(tmp!=0) {
pr_tmp*=pr;
tmp=parent[tmp];
}
ans+=pr_tmp*leaf[i].amount;
}
printf("%.1lf",ans*p);
}