起初误以为到每个叶子的概率一样于是....

/*
CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2)
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
vector<int> G[N];
double dp[N], val[N];
bool vis[N];
void dfs(int u, int pre)
{
bool flag = 0;
for (auto&v : G[u])
{
if (v == pre) continue;
flag = 1;
dp[v] = dp[u]+1;
val[v] = val[u] / (G[u].size()-1);
dfs(v, u);
}
if (!flag) vis[u] = 1;
}
int main()
{
scanf("%d", &n);
for (int i = 1; i < n; i++)
{
int u, v; scanf("%d%d", &u, &v);
G[u].push_back(v);
G[v].push_back(u);
}
G[1].push_back(1);
val[1] = 1;
dfs(1, 1);
int cnt = 0;
double ans = 0;
for (int i = 1; i <= n; i++)
if (vis[i]) ans += dp[i]*val[i];
printf("%.15f\n", ans);
}

  

CodeForces 839C - Journey | Codeforces Round #428 (Div. 2)的更多相关文章

  1. CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)

    赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...

  2. CodeForces 839B - Game of the Rows | Codeforces Round #428 (Div. 2)

    血崩- - /* CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2) 注意 2 7 2 2 2 ...

  3. 【Codeforces Round #428 (Div. 2) C】Journey

    [Link]:http://codeforces.com/contest/839/problem/C [Description] 给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是 ...

  4. Codeforces Round #428 (Div. 2) C. Journey (简单搜索)

    题意:给你一颗树(边是无向的),从根节点向下走,统计走到每个子节点的概率,求所有叶子节点的深度乘上概率的和. 题解:每层子节点的概率等于上一层节点的概率乘\(1\)除以这层的子节点数,所以我们用\(d ...

  5. Codeforces Round #428 (Div. 2) 题解

    题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...

  6. Codeforces Round #428 (Div. 2) D. Winter is here 容斥

    D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...

  7. Codeforces Round #428 (Div. 2)E. Mother of Dragons

    http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...

  8. 【Codeforces Round #428 (Div. 2) B】Game of the Rows

    [Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...

  9. Codeforces Round #428 (Div. 2)A,B,C

    A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. [转帖]phoronix-test-suite测试云服务器

    phoronix-test-suite测试云服务器 https://www.cnblogs.com/tanyongli/p/7767804.html centos系统 phoronix-test-su ...

  2. 【转帖】深挖NUMA

    深挖NUMA http://www.litrin.net/2017/10/31/深挖numa/ 首先列出本站之前相关的几篇帖子: Linux的NUMA机制 NUMA对性能的影响 cgroup的cpus ...

  3. [转帖]【Oracle】详解Oracle中NLS_LANG变量的使用

    [Oracle]详解Oracle中NLS_LANG变量的使用 https://www.cnblogs.com/HDK2016/p/6880560.html NLS_LANG=LANGUAGE_TERR ...

  4. (一)springMvc 底层运作流程

    目录 什么是 springMvc SpringMVC的底层运作流程 什么是 springMvc springMvc 是spring 框架的一个模块,这也就意味着二者不需要通过整合层(整合包)进行整合 ...

  5. Do Not Try This Problem(分块思想)

    题意:https://codeforces.com/group/ikIh7rsWAl/contest/259944/problem/D 给你q个操作,4个数n,a,k,c,从n好位置开始每次加a的位置 ...

  6. 适合新手的160个creakme(四)

    这题没有什么特殊字符串,Delphi写的,使用DeDeDark分析一下,找到几个特殊的事件 一个是KeyUp 一个是chkcode 还有就是中间区域的单击或是双击事件 直接跟进去这几个函数,然后找比较 ...

  7. shell习题第16题:查用户

    [题目要求] 写个shell,看看你的Linux系统中是否有自定义的用户(普通用户),如有有的话统计个数 [核心要点] CentOS6,uid>=500 CentOS7,uid>=1000 ...

  8. Java 8 Collectors 类的静态工厂方法

    摘自<<Java 8 实战>> Collectors 类的静态工厂方法 工厂方法 返回类型 用于 toList List<T>  把流中所有项目收集到一个 List ...

  9. C语言——指针总结

    在创建指针时,我们首先要做的是先初始化它,没有初始化的指针是很危险的,因为指针可以指向一个地址后直接改变它的值,所以为了避免我们的指针在创建后指向一个危险区域(即可能指向系统文件等),我们会先给它一个 ...

  10. asp.net ListView控件的简单实用和配置

    1 web窗体界面代码 ItemType:控件要绑定的实体模型 SelectMethod:控件获取实体集合的后台方法 DataKeyNames:实体的主键 UpdateProduct:设置跟新的方法 ...