Bzoj 3566: [SHOI2014] Probability charger

Source: Internet
Author: User

Title: http://www.lydsy.com/JudgeOnline/problem.php?id=3566

First of all, the problem is to think about, consider complementary set transformation.

DFS first, so that f[u]= (1-p[u]) *∏ (n (1-f[v]) *w) F[u] means that the point of you through its sub-tree and can not be connected to the probability.

Then consider v from his father connected to the situation, set x=1-f[u]/(1-f[v]) *w to remove the probability of V,u Unicom, then f[v]*= (1-x*w)

And then add up is the answer.

#include <cstring>#include<iostream>#include<algorithm>#include<cstdio>#defineMAXN 500500#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#defineEPS 1e-8using namespacestd;structdata{intObj,pre;DoubleC;} E[MAXN*2];intHead[maxn],tot,n;DoubleF[MAXN],ANS,P[MAXN];intRead () {intx=0, f=1;CharCh=GetChar ();  while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();}  while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}voidInsertintXintYDoublez) {e[++tot].obj=y; E[tot].c=z; E[TOT].PRE=HEAD[X]; head[x]=tot;}voidDfsintUintFA) {F[u]=1-P[u];  for(intj=head[u];j;j=e[j].pre) {        intv=E[j].obj; if(v!=FA)             {DFS (V,U); F[u]=f[u]* (1-(1-F[V]) *e[j].c); }     }}voidGointUintFA) {     for(intj=head[u];j;j=e[j].pre) {        intv=E[j].obj; if(v!=FA) {            Doublex=1-f[u]/(1-(1-F[V]) *e[j].c); if(x>eps&&f[v]>eps) f[v]=f[v]* (1-x*e[j].c);        Go (v,u); }    }}intMain () {n=read (); Rep (I,1, N-1){        intX=read (), Y=read (), z=read (); Insert (x, Y,1.0*z/ -); Insert (Y,x,1.0*z/ -); } Rep (I,1, N) {intX=read (); p[i]=1.0*x/ -;} DFS (1,0); Go (1,0); Rep (I,1, N) ans+=1-F[i]; printf ("%.6lf\n", ans); return 0;}

Bzoj 3566: [SHOI2014] Probability charger

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.