bzoj3566 [SHOI2014]概率充电器

Description

“采用全新纳米级加工技术,实现元件与导线能否通电完全由真随机数决定!SHOI 概率充电器,您生活不可或缺的必需品!能充上电吗?现在就试试看吧!”
SHOI 概率充电器由 n-1 条导线连通了 n 个充电元件。进行充电时,每条导线是否可以导电以概率决定,每一个充电元件自身是否直接进行充电也由概率决定。

3
1 2 50
1 3 50
50 0 0

1.000000

HINT

 1 //It is made by wfj_2048~
2 #include <algorithm>
3 #include <iostream>
4 #include <complex>
5 #include <cstring>
6 #include <cstdlib>
7 #include <cstdio>
8 #include <vector>
9 #include <cmath>
10 #include <queue>
11 #include <stack>
12 #include <map>
13 #include <set>
14 #define inf (1<<30)
15 #define eps (1e-9)
16 #define N (500010)
17 #define il inline
18 #define RG register
19 #define ll long long
20 #define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
21
22 using namespace std;
23
24 struct edge{ int nt,to; long double dis; }g[2*N];
25
26 long double f[N],p[N],ans;
28
29 il int gi(){
30     RG int x=0,q=1; RG char ch=getchar();
31     while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
32     if (ch=='-') q=-1,ch=getchar();
33     while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
34     return q*x;
35 }
36
37 il void insert(RG int from,RG int to,RG long double dis){
39 }
40
41 il void dfs1(RG int x,RG int fa){
42     RG int v; f[x]=1-p[x];
44     v=g[i].to; if (v==fa) continue;
45     dfs1(v,x),f[x]*=1-(1-f[v])*g[i].dis;
46     }
47     return;
48 }
49
50 il void dfs2(RG int x,RG int fa){
51     RG int v; RG long double res;
53     v=g[i].to; if (v==fa) continue;
54     res=1-f[x]/(1-(1-f[v])*g[i].dis);
55     if (res>eps && f[v]>eps) f[v]*=1-res*g[i].dis;
56     dfs2(v,x);
57     }
58     return;
59 }
60
61 il void work(){
62     n=gi(); RG int u,v,w; RG long double z;
63     for (RG int i=1;i<n;++i){
64     u=gi(),v=gi(),w=gi(),z=1.0*w/100;
65     insert(u,v,z),insert(v,u,z);
66     }
67     for (RG int i=1;i<=n;++i) w=gi(),p[i]=1.0*w/100;
68     dfs1(1,0),dfs2(1,0); for (RG int i=1;i<=n;++i) ans+=1-f[i];
69     printf("%0.6Lf\n",ans); return;
70 }
71
72 int main(){
73     File("3566");
74     work();
75     return 0;
76 }

posted @ 2017-04-13 20:58  wfj_2048  阅读(723)  评论(0编辑  收藏  举报