codeforces 220 C. Game on Tree
题目链接
codeforces 220 C. Game on Tree
题解
对于 1节点一定要选的
发现对于每个节点,被覆盖切选中其节点的概率为祖先个数分之一,也就是深度分之一
代码
#include<cstdio>
#include<algorithm>
const int maxn = 1000007;
struct node {
int u,v,next;
} edge[maxn << 1] ;
int head[maxn],num = 0;
inline void add_edge(int u,int v) {
edge[++ num].v = v;edge[num].next = head[u] ;head[u] = num;
}
int n;
double ans = 0;
double dep[maxn];
void dfs(int x,int fa) {
ans += (1 / dep[x]);
for(int i = head[x]; i; i = edge[i].next) {
int v = edge[i].v;
if(v == fa)continue;
dep[v] = dep[x] + 1.0;
dfs(v,x);
}
}
int main() {
scanf("%d",&n);
for(int u,v,i = 1;i < n;++ i){
scanf("%d%d",&u,&v);
add_edge(u,v);add_edge(v,u) ;
}
dep[1] = 1;
dfs(1,0);
printf("%.10lf",ans);
return 0;
}
codeforces 220 C. Game on Tree的更多相关文章
- codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(启发式合并)
codeforces 741D Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths 题意 给出一棵树,每条边上有一个字符,字符集大小只 ...
- codeforces 812E Sagheer and Apple Tree(思维、nim博弈)
codeforces 812E Sagheer and Apple Tree 题意 一棵带点权有根树,保证所有叶子节点到根的距离同奇偶. 每次可以选择一个点,把它的点权删除x,它的某个儿子的点权增加x ...
- Codeforces E. Alyona and a tree(二分树上差分)
题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 379 F. New Year Tree
\(>Codeforces \space 379 F. New Year Tree<\) 题目大意 : 有一棵有 \(4\) 个节点个树,有连边 \((1,2) (1,3) (1,4)\) ...
- 【27.91%】【codeforces 734E】Anton and Tree
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces 342E :Xenia and Tree
Description Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes i ...
- Codeforces Edu3 E. Minimum spanning tree for each edge
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- codeforces 682C Alyona and the Tree(DFS)
题目链接:http://codeforces.com/problemset/problem/682/C 题意:如果点v在点u的子树上且dist(u,v)>a[v]则u和其整个子树都将被删去,求被 ...
- Codeforces 161 D. Distance in Tree (树dp)
题目链接:http://codeforces.com/problemset/problem/161/D 题意: 给你一棵树,问你有多少对点的距离为k. 思路: dp[i][j]表示离i节点距离为j的点 ...
随机推荐
- asp.net DataTable导出 excel的方法记录(第三方)
官网:http://npoi.codeplex.com/ 简单应用,主要是可以实现我们想要的简单效果,呵呵 需要引入dll,可以在官网下载,也可在下面下载 protected void getExce ...
- 【BZOJ】4756: [Usaco2017 Jan]Promotion Counting
[题意]带点权树,统计每个结点子树内点权比它大的结点数. [算法]线段树合并 [题解]对每个点建权值线段树(动态开点),DFS中将自身和儿子线段树合并后统计. 注意三个量tot,cnt,tots,细心 ...
- 解决爬虫时网站采用gb2312编码所遇到的乱码问题!
import requests from bs4 import BeautifulSoupall_url = 'http://www.7160.com/qingchunmeinv/' # 请求头 he ...
- C++ STL标准入门
C++:STL标准入门汇总 第一部分:(参考百度百科) 一.STL简介 STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称.它是由Alexand ...
- Ubuntu 17.10 用 apt 搭建 lamp 环境、安装 phpmyadmin、redis 服务+扩展、mysql 扩展、开启错误提示、配置虚拟主机
2018-02-24 13:50:30 更新: 个人喜欢相对原生又不太麻烦,所以用 apt 构建环境.不过,最近使用到现在记得出现过了 3 次 apache 或 mysql 服务器无法启动或无法连接的 ...
- ubuntu10.04 svn安装方法
ubuntu10.04 svn安装方法:sudo apt-get install subversion sudo apt-get install libneon27-dev orsudo apt-ge ...
- elk系列4之kibana图形化操作【转】
preface 我们都搭建了ELK系统,且日志也能够正常收集的时候,那么就配置下kibana.我们可以通过kibana配置柱状图,趋势图,统计图,圆饼图等等各类图.下面就拿配置统计图和柱状图为例,结合 ...
- 在Linux上安装pycharm
1.首先在官网下载pycharm并进行提取,将提取的文件夹放在/usr下面(或者任意位置) 2.然后vi /etc/hosts 编辑 将0.0.0.0 account.jetbrains.com添加到 ...
- php琐碎
1.类中的常量,可以用类来引用: class MyClass() { const SUCCESS ="success"; const FAIL ="fail"; ...
- 一张图解AlphaGo原理及弱点
声明:本文转载自(微信公众号:CKDD),作者郑宇 张钧波,仅作学习收录之用,不做商业目的. 近期AlphaGo在人机围棋比赛中连胜李世石3局,体现了人工智能在围棋领域的突破,作为人工智能领域的工作者 ...