CodeForces 839C - Journey | Codeforces Round #428 (Div. 2)
起初误以为到每个叶子的概率一样于是....
/*
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)的更多相关文章
- CodeForces 839D - Winter is here | Codeforces Round #428 (Div. 2)
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Di ...
- 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 ...
- 【Codeforces Round #428 (Div. 2) C】Journey
[Link]:http://codeforces.com/contest/839/problem/C [Description] 给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是 ...
- Codeforces Round #428 (Div. 2) C. Journey (简单搜索)
题意:给你一颗树(边是无向的),从根节点向下走,统计走到每个子节点的概率,求所有叶子节点的深度乘上概率的和. 题解:每层子节点的概率等于上一层节点的概率乘\(1\)除以这层的子节点数,所以我们用\(d ...
- Codeforces Round #428 (Div. 2) 题解
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部 ...
- 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 ...
- Codeforces Round #428 (Div. 2)E. Mother of Dragons
http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大 ...
- 【Codeforces Round #428 (Div. 2) B】Game of the Rows
[Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4) ...
- 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 ...
随机推荐
- 【转帖】龙芯将两款 CPU 核开源,这意味着什么?
龙芯将两款 CPU 核开源,这意味着什么? https://www.oschina.net/news/78316/loongson-open-source-two-cpu-core 文章挺不错的 也讲 ...
- Linux上面mount 域控的目录 超时 然后提示 error的解决办法
mount error(112): Host is down 故障解决 https://blog.csdn.net/lepton126/article/details/89447713 之前查到过 这 ...
- LeetCode 第 165 场周赛
LeetCode 第 165 场周赛 5275. 找出井字棋的获胜者 5276. 不浪费原料的汉堡制作方案 5277. 统计全为 1 的正方形子矩阵 5278. 分割回文串 III C 暴力做的,只能 ...
- 注解@PostConstruct与@PreDestroy详解及实例
Java EE5 引入了@PostConstruct和@PreDestroy这两个作用于Servlet生命周期的注解,实现Bean初始化之前和销毁之前的自定义操作.此文主要说明@PostConstru ...
- java http接口请求响应 request response
接口类: 1 package org.sunshine.dcda.epg.wechat.controller.niao; 2 3 import javax.servlet.http.HttpServl ...
- ubuntu 拨号上网
如果没有安装的用户,可以使用 sudo apt-get install pppoe pppoeconf 然后配置上网 sudo pppoeconf 最后,使用 sudo pon dsl-provide ...
- 题目12 打印1到最大的n位数
///////////////////////////////////////////////////////////////////////////////////// // 2.打印1到最大的n位 ...
- Python 第二式
@Codewars Python练习 question ** Simple transposition ** Simple transposition is a basic and simple cr ...
- 贝叶斯优化 Bayesian Optimization
贝叶斯优化 Bayesian Optimization 2018年07月02日 22:28:06 余生最年轻 阅读数 4821更多 分类专栏: 机器学习 版权声明:本文为博主原创文章,遵循CC 4 ...
- redis 入门教程
https://edu.aliyun.com/course/22/lesson/list?spm=5176.8252056.759075.5.Bbrpyz