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 ...
随机推荐
- Git初始化配置以及配置github
1,配置用户名和邮箱(这里是我github中配置的用户名和邮箱),执行下面命令后,在C:\Users\yaosq盘下会出现一个全局文件.gitconfig. git config --global u ...
- select key from table 一直出错
key和keys 为mysql 关键字,数据库设计字段的时候尽量避免
- python爬取信息并保存至csv
import csv import requests from bs4 import BeautifulSoup res=requests.get('http://books.toscrape.com ...
- C#连接Oracle数据库的方法
目前了解C#中连接Oracle数据库的方法有3种,分布是微软的System.Data.OracleClient,Oracle的Oracle.DataAccess.Client和Oracle的Oracl ...
- 【原创】大叔经验分享(83)impala执行多个select distinct
impala在一个select中执行多个count distinct时会报错,比如执行 select key, count(distinct column_a), count(distinct col ...
- C#学习资料
http://www.runoob.com/csharp/csharp-delegate.html
- Qt的多线程总结以及使用(一)
Qt提供QThread类以进行多任务的处理.Qt提供的线程可以做到单个进程做不到的事情.在这里实现最简单的一个多线程.最简单的线程的基类为QThread,然后需要重写QThread的run(),在ru ...
- NPOI 实现在已存在的Excel中任意位置开始插入任意数量行,并填充数据
1 npoi版本2.1.3.1 2 需要添加的引用: using NPOI.SS.UserModel;using NPOI.XSSF.UserModel;using System.IO;using N ...
- sql 创建新表时的完成格式
1 create table [dbo].[Customer] ( CustomerID int identity(1,1) not null, [Name] [nvarchar](50) null, ...
- Java秒杀实战 (三)秒杀基本功能开发
转自:https://blog.csdn.net/qq_41305266/article/details/80991687 一.两次MD5 1. 用户端: PASS = MD5( 明文 + 固定 Sa ...