简单 d p dp dp
考虑到充的上电的概率不好求
求出每个点充不上点的概率减一下就完了
令
f
[
i
]
f[i]
f[i]表示
i
i
i的儿子们没法给自己充电或自己没电的概率
g
[
i
]
g[i]
g[i]表示
i
i
i的父亲没法给自己充电的概率
h
[
i
]
h[i]
h[i]表示
i
i
i没法给父亲充电的概率
那显然
h
[
i
]
=
f
[
i
]
+
(
1
−
f
[
i
]
)
∗
p
i
,
f
a
i
h[i]=f[i]+(1-f[i])*p_{i,fa_i}
h[i]=f[i]+(1−f[i])∗pi,fai
f
[
i
]
=
(
1
−
q
[
i
]
)
∗
h
[
s
o
n
i
]
f[i]=(1-q[i])*h[son_i]
f[i]=(1−q[i])∗h[soni]
t
=
g
[
f
a
[
i
]
]
∗
f
[
f
a
[
i
]
]
h
[
i
]
,
g
[
i
]
=
t
+
(
1
−
t
)
∗
(
1
−
p
i
,
f
a
i
)
t=g[fa[i]]*\frac{f[fa[i]]}{h[i]},g[i]=t+(1-t)*(1-p_{i,fa_i})
t=g[fa[i]]∗h[i]f[fa[i]],g[i]=t+(1−t)∗(1−pi,fai)
#include<bits/stdc++.h>
using namespace std;
inline int read(){
char ch=getchar();
int res=0,f=1;
while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=getchar();
return res*f;
}
const int N=500005;
int n,adj[N],nxt[N<<1],to[N<<1],cnt;
double f[N],g[N],h[N],p[N<<1],val[N],q[N],ans;
inline void addedge(int u,int v,double w){
nxt[++cnt]=adj[u],adj[u]=cnt,to[cnt]=v,p[cnt]=w;
}
inline void dfs1(int u,int fa){
f[u]=1.0-q[u];
for(int e=adj[u];e;e=nxt[e]){
int v=to[e];
if(v==fa)continue;
val[v]=p[e];
dfs1(v,u);
f[u]*=h[v];
}
h[u]=f[u]+(1.0-f[u])*(1-val[u]);
}
inline void dfs2(int u,int fa){
for(int e=adj[u];e;e=nxt[e]){
int v=to[e];
if(v==fa)continue;
double t=g[u]*f[u]/h[v];
g[v]=t+(1.0-t)*(1-p[e]);
dfs2(v,u);
}
}
int main(){
n=read();
for(int i=1;i<n;i++){
int u=read(),v=read(),w=read();
double s=w*1.0/100;
addedge(u,v,s),addedge(v,u,s);
}
for(int i=1;i<=n;i++)q[i]=read()*1.0/100;
dfs1(1,0);
dfs2(g[1]=1,0);
for(int i=1;i<=n;i++)ans+=1.0-f[i]*g[i];
printf("%.6lf",ans);
}