Main idea:
Give you a tree, each point has the probability of direct power, each side has the probability of conducting electricity. Find out the expected power saving points.
Ideas:
At the beginning, I thought of Gauss elimination, each side is a mess of things, and then I found myself in a mess, I used the linearity of probability to make a n^2 violence, and then I handed it in.
The positive solution is also very simple. Because of the expected linearity, the answer is the sum of the power on probability of each point. Then, because the contribution of each point can only be transferred from the connected edge without any aftereffect, we can set f,g as the expectation of searching from top to bottom and from bottom to top. At last, we can get the expectation of each point directly.
Procedure:
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define N 500001
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
#define fr(i,j) for(int i=last[j];i;i=e[i].next)
using namespace std;
int n,cnt,q[N],inq[N];
double f[N],g[N],h[N],last[N],a[N];
struct data{int to,next;double w;}e[N*2];
void add(int x,int y,double w){
e[++cnt].to=y; e[cnt].w=w; e[cnt].next=last[x]; last[x]=cnt;
e[++cnt].to=x; e[cnt].w=w; e[cnt].next=last[y]; last[y]=cnt;
}
void dfs1(int u,int fa){
for (int i=last[u];i;i=e[i].next){
int v=e[i].to;
if (v==fa) continue;
dfs1(v,u);
h[v]=f[v]+(1-f[v])*(1-e[i].w);
f[u]*=h[v];
}
}
void dfs2(int u,int fa){
for (int i=last[u];i;i=e[i].next){
int v=e[i].to;
double t;
if (v==fa) continue;
t=h[v]<1e-6?0:g[u]*f[u]/h[v];
g[v]=t+(1-t)*(1-e[i].w);
dfs2(v,u);
}
}
int main(){
freopen("charger.in","r",stdin);
freopen("charger.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<n;i++){
int a,b;
double p;
scanf("%d%d%lf",&a,&b,&p);
p=p/100;
add(a,b,p);
}
for (int i=1;i<=n;i++){
scanf("%lf",&a[i]);
a[i]=a[i]/100;
}
/* dfs1(1,0);
g[1]=1;
dfs2(1,0);*/
int ti=0;
inq[q[++ti]=1]=1;
fo(i,1,n){
int now=q[i];
fr(j,now)if(!inq[e[j].to])inq[q[++ti]=e[j].to]=1;
}
fo(i,1,n)inq[i]=0;
fd(i,n,1){
int now=q[i];inq[now]=1;
f[now]=1-a[now];
fr(j,now)if(inq[e[j].to]){
f[now]*=1-e[j].w*(1-f[e[j].to]);
}
}
g[1]=1;
fo(i,1,n)inq[i]=0;
fo(i,1,n){
int now=q[i];inq[now]=1;
fr(j,now)if(!inq[e[j].to]){
if(1-e[j].w*(1-f[e[j].to]))g[e[j].to]=1-e[j].w*(1-f[now]*g[now]/(1-e[j].w*(1-f[e[j].to])));
else g[e[j].to]=1-e[j].w;
}
}
double ans=0;
for (int i=1;i<=n;i++) ans+=1-f[i]*g[i];
printf("%.6lf",ans);
}