传送门

分析

见ptx大爷的博客

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int siz[],n;
vector<int>v[];
double Ans,a[],b[],tota,totb;
inline void dfs(int x,int fa){
int i,j,k;
siz[x]=;
for(i=;i<v[x].size();i++)
if(v[x][i]!=fa){
dfs(v[x][i],x);
siz[x]+=siz[v[x][i]];
a[x]+=a[v[x][i]];
Ans+=(double)a[v[x][i]]*siz[v[x][i]]*b[x];
}
Ans+=(double)(tota-a[x])*(n-siz[x])*b[x];
}
int main(){
int i,j,k;
scanf("%d",&n);
for(i=;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}
for(i=;i<=n;i++){
scanf("%lf%lf",&a[i],&b[i]);
tota+=a[i];
totb+=b[i];
}
dfs(,);
printf("%0.10lf\n",Ans/tota/totb);
return ;
}

cf123E Maze的更多相关文章

  1. CF123E Maze(期望dp,树形dp,式子)

    题目大意: 给你一棵树,边权都是1,每一个点有一个是起点的概率和一个是终点的概率,你将以起点为根,开始在树上随机dfs,每到一个点,就会将他的所有儿子随机打乱成序列,然后按照那个随机顺序走完,直到走到 ...

  2. 【CF123E】Maze

    Portal --> cf123E Solution 首先步数的话可以转化成每条边经过了几次这样来算 假设现在确定了起点\(S\)和终点\(T\),我们将\(T\)看成树根,那么考虑边\((u, ...

  3. Backtracking algorithm: rat in maze

    Sept. 10, 2015 Study again the back tracking algorithm using recursive solution, rat in maze, a clas ...

  4. (期望)A Dangerous Maze(Light OJ 1027)

    http://www.lightoj.com/volume_showproblem.php?problem=1027 You are in a maze; seeing n doors in fron ...

  5. 1204. Maze Traversal

    1204.   Maze Traversal A common problem in artificial intelligence is negotiation of a maze. A maze ...

  6. uva705--slash maze

    /*这道题我原本是将斜线迷宫扩大为原来的两倍,但是在这种情况下对于在斜的方向上的搜索会变的较容易出错,所以参考了别人的思路后将迷宫扩展为原来的3倍,这样就变成一般的迷宫问题了*/ #include&q ...

  7. HDU 4048 Zhuge Liang's Stone Sentinel Maze

    Zhuge Liang's Stone Sentinel Maze Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/327 ...

  8. Borg Maze(MST & bfs)

    Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9220   Accepted: 3087 Descrip ...

  9. poj 3026 bfs+prim Borg Maze

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9718   Accepted: 3263 Description The B ...

随机推荐

  1. java学习笔记--常用类

    一.Math类:针对数学运算进行操作的类 1.常用的方法 A:绝对值   public static int abs(int a) B:向上取整  public static double ceil( ...

  2. CodeForces - 156D:Clues(矩阵树定理&并查集)

    题意:给定N点,M边,求添加最少的边使之变为连通图的方案数. 思路:注意题目给出的M边可能带环,即最后生成的不一定是一棵树.但是影响不大.根据矩阵树定理,我们知道生成树的数量=N^(N-2),即点数^ ...

  3. PADS Layout CAM 的中高级焊盘选项

    PADS Layout CAM 的中高级焊盘选项 PADS CAM Gerber 输出非常灵活. 以至于很多人跳坑. 以这个这选项,最好的方式就是不勾.

  4. (转载)Windows: "net use" command introduction

    1)建立空连接: net use ""IP"ipc$ "" /user:"" (一定要注意:这一行命令中包含了3个空格) 2)建立 ...

  5. keepalived 检测脑裂切换脚本

    #!/bin/bash count=0 run1=`curl -I 192.168.30.12:8000 | grep "200 OK" | wc -l` run2=`curl - ...

  6. LeetCode第五题:Longest Palindromic Substring

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...

  7. 在Azure New Portal上创建基于ARM的带SLB的VM

    目前Azure的New Portal在国内已经上线了.本文将介绍最常见的一种场景:通过Azure的New Portal创建带有Server Load Balance的多台虚拟机. 1 创建Resour ...

  8. declare handler 声明异常处理的语法

    声明异常处理的语法 DECLARE {EXIT | CONTINUE} HANDLER FOR {error-number | SQLSTATE error-string | condition} S ...

  9. pom.xm首行报错Failure to transfer org.codehaus.plexus:plexus-components:pom:1.1.20

    从SVN导出一个Maven项目,pom.xml首行报错: Failure to transfer org.codehaus.plexus:plexus-components:pom:1.1.20 fr ...

  10. PostgreSQL recovery.conf恢复配置

    PostgreSQL recovery.conf恢复配置 这一章描述recovery.conf 文件中可用的设置.它们只应用于恢复期.对于你希望执行的任意后续恢复, 它们必须被重置.一旦恢复已经开始, ...