题目链接

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的更多相关文章

  1. 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 题意 给出一棵树,每条边上有一个字符,字符集大小只 ...

  2. codeforces 812E Sagheer and Apple Tree(思维、nim博弈)

    codeforces 812E Sagheer and Apple Tree 题意 一棵带点权有根树,保证所有叶子节点到根的距离同奇偶. 每次可以选择一个点,把它的点权删除x,它的某个儿子的点权增加x ...

  3. Codeforces E. Alyona and a tree(二分树上差分)

    题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. Codeforces 379 F. New Year Tree

    \(>Codeforces \space 379 F. New Year Tree<\) 题目大意 : 有一棵有 \(4\) 个节点个树,有连边 \((1,2) (1,3) (1,4)\) ...

  5. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. codeforces 342E :Xenia and Tree

    Description Xenia the programmer has a tree consisting of n nodes. We will consider the tree nodes i ...

  7. 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 ...

  8. codeforces 682C Alyona and the Tree(DFS)

    题目链接:http://codeforces.com/problemset/problem/682/C 题意:如果点v在点u的子树上且dist(u,v)>a[v]则u和其整个子树都将被删去,求被 ...

  9. Codeforces 161 D. Distance in Tree (树dp)

    题目链接:http://codeforces.com/problemset/problem/161/D 题意: 给你一棵树,问你有多少对点的距离为k. 思路: dp[i][j]表示离i节点距离为j的点 ...

随机推荐

  1. c++都忘记了,看了看那本发黄的C++primer,还是要去翻下了

    char *s="string"和char s[]="string"的区别 void main() { char* pStr1 = "Hello!&q ...

  2. 【洛谷 P4219】 [BJOI2014]大融合(LCT)

    题目链接 维护子树信息向来不是\(LCT\)所擅长的,所以我没搞懂qwq 权当背背模板吧.Flash巨佬的blog里面写了虽然我没看懂. #include <cstdio> #define ...

  3. 垂直水平居中--css3

    在移动前端制作中,很多新的css3特性能够帮助我们更好的制作.例如这个垂直水平居中问题,就有一个简单的代码可以解决: 利用CSS3的transform:translate .center{ width ...

  4. HDU 1045 Fire Net (深搜)

    题目链接 Problem DescriptionSuppose that we have a square city with straight streets. A map of a city is ...

  5. gitlab使用 —— 多人协同工作(重要技能)

    gitlab使用 —— 多人协同工作(重要技能) 学习链接: http://herry2013git.blog.163.com/blog/static/219568011201341111240751 ...

  6. VC调用易语言DLL

    易语言方面: .版本 .子程序 show, , 公开 ' 本名称子程序用作测试程序用,仅在开发及调试环境中有效,编译发布程序前将被系统自动清空,请将所有用作测试的临时代码放在本子程序中. ***注意不 ...

  7. notepad++突然崩溃,保存的文件没了怎么办

    在C:\Users\你当前用户的用户名\AppData\Roaming\Notepad++\backup  有备份

  8. PHP对象5: define / const /static

    define定义全局常量: define('PATH', '/data/home/www'); const也是定义常量, 一般用于类中, 饰成员属性,不可以修饰方法,如下: class Test{ c ...

  9. GO-指针与函数

    一.指针类型 1.普通类型,变量存的就是值,也叫值类型.指针类型存的是地址 2.获取变量的地址,用&,比如:var a int, 获取a的地址 &a 3.指针类型,变量存的是一个地址, ...

  10. onvif客户端

    前言 做开发有8年时间了,ffmpeg和onvif与我是特别有缘的了(说着玩的,我更认为是因为他们确实强大^_^). ffmpeg在毕业设计时就有用到,5年后做windows.linux播放库时又有用 ...