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

/*
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. 【AtCoder】ARC065

    ARC065 C - 白昼夢 / Daydream 直接递推就好 #include <bits/stdc++.h> #define fi first #define se second # ...

  2. 【计算机网络】-传输层-Internet传输协议-TCP

    [计算机网络]-传输层-Internet传输协议-TCP TCP介绍 在不可靠的互联网上提供一个可靠的端到端字节流 面向连接的.可靠的.端到端的.基于字节流的传输协议 TCP位置 TCP服务模型 应用 ...

  3. 网络流基础&网络流24题

    网络最大流 dinic+当前弧优化. const int N=10007,M=100007,inf=1e9; int s,t,head[N],ver[M],edge[M],Next[M],tot=1, ...

  4. Go-环境搭建-hello world-变量常量定义-函数使用基础

    目录 编程语言科普 常见语言的背景 go 为什么这么火? 环境搭建(很重要) ide 编辑器 注释 第一个程序 Hello world! 编译与执行 变量类型 数字类型 字符串类型 布尔类型 常量 函 ...

  5. 选择最佳策略:简单的方式和globals()

    promos = [fidelity_promo, bulk_item_promo, large_order_promo] ➊ def best_promo(order): ➋ "" ...

  6. k8s之RBAC-基于角色的访问控制

    一个在名称空间内的对象的完整url模板: Object_URL: /apis/<GROUP>/<VERSION>/namespaces/<NAMESPACE_NAME&g ...

  7. 1、ECharts(中国地图篇)的使用

    一.网址:            http://echarts.baidu.com/download.html点击:            完整下载文件:        echarts.min.js ...

  8. eclipse 创建聚合maven项目(转)

    转自https://blog.csdn.net/u013239111/article/details/76560167 以前我们搭建项目时,通常是吧pojo.dao.service.配置文件等都放在一 ...

  9. Redis 的订阅发布(PUB/SUB)示例

    ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("127.0.0.1"); ISubscriber sub ...

  10. Ubuntu 上网

    1.打开终端 2.sudo gedit /etc/wpa_supplicant/wpa_supplicant.conf(回车之后会弹出一个编辑页面,在里面打入第三步里面的配置文件)3.配置文件如下:c ...