日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

*【CodeForces - 280C】Game on Tree(期望模型,期望的线性性)

發布時間:2023/12/10 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 *【CodeForces - 280C】Game on Tree(期望模型,期望的线性性) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Momiji has got a rooted tree, consisting of?n?nodes. The tree nodes are numbered by integers from?1?to?n. The root has number?1. Momiji decided to play a game on this tree.

The game consists of several steps. On each step, Momiji chooses one of the remaining tree nodes (let's denote it by?v) and removes all the subtree nodes with the root in node?v?from the tree. Node?v?gets deleted as well. The game finishes when the tree has no nodes left. In other words, the game finishes after the step that chooses the node number?1.

Each time Momiji chooses a new node uniformly among all the remaining nodes. Your task is to find the expectation of the number of steps in the described game.

Input

The first line contains integer?n?(1?≤?n?≤?105)?— the number of nodes in the tree. The next?n?-?1?lines contain the tree edges. The?i-th line contains integers?ai,?bi(1?≤?ai,?bi?≤?n;?ai?≠?bi)?— the numbers of the nodes that are connected by the?i-th edge.

It is guaranteed that the given graph is a tree.

Output

Print a single real number — the expectation of the number of steps in the described game.

The answer will be considered correct if the absolute or relative error doesn't exceed?10?-?6.

Examples

Input

2 1 2

Output

1.50000000000000000000

Input

3 1 2 1 3

Output

2.00000000000000000000

Note

In the first sample, there are two cases. One is directly remove the root and another is remove the root after one step. Thus the expected steps are:

1?×?(1?/?2)?+?2?×?(1?/?2)?=?1.5

In the second sample, things get more complex. There are two cases that reduce to the first sample, and one case cleaned at once. Thus the expected steps are:

1?×?(1?/?3)?+?(1?+?1.5)?×?(2?/?3)?=?(1?/?3)?+?(5?/?3)?=?2

題目大意:

給一顆n個點有根的樹,每次任意刪一個當前還存在的點,并刪掉其子樹,問刪完整顆樹的刪點次數的數學期望。

解題報告:

琢磨了半天,似懂非懂,先記下來以后再加深理解吧。

考慮等價問題:對于每一個點,假設考慮第i個點,選擇刪第i個點的平均次數 的和。

既然最終第i個點肯定要被刪除的,那么肯定是他和他到根節點這一條鏈上的節點 都可以做到,那么其中假設深度為d,那么選擇這個點的概率就是,那么對所有的點求個和就是答案。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define F first #define S second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; int dep[MAX],n; vector<int> vv[MAX]; void dfs(int cur,int fa,int d) {dep[cur] = d;for(int i = 0; i<vv[cur].size(); i++) {if(vv[cur][i] == fa) continue;dfs(vv[cur][i],cur,d+1);} } int main() {cin>>n;for(int a,b,i = 1; i<=n-1; i++) cin>>a>>b,vv[a].pb(b),vv[b].pb(a);dfs(1,-1,1);double ans = 0;for(int i = 1; i<=n; i++) {ans += 1.0/dep[i];}printf("%.10f\n",ans);return 0 ; }

?

總結

以上是生活随笔為你收集整理的*【CodeForces - 280C】Game on Tree(期望模型,期望的线性性)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 性欧美成人播放77777 | 国产日视频| 网站在线观看你懂的 | 日韩v欧美| 天堂а√在线最新版中文在线 | 在线看成人片 | 国产精品二区一区二区aⅴ污介绍 | 夜色视频在线观看 | 亚洲精品乱码久久久久久黑人 | www国产视频 | 亚洲色偷精品一区二区三区 | 久久久免费高清视频 | 一区二区三区久久 | 久久r精品 | 青青欧美 | 在线香蕉 | 欧美高清v | 一个色亚洲 | 欧美日一区二区三区 | 51妺嘿嘿午夜福利 | 中文字幕第十二页 | 国产 日韩 欧美 成人 | 国产主播在线一区 | 欧美顶级少妇做爰hd | 国产精品久久国产精品99 | h网站在线播放 | 国产男女精品 | 夜噜噜 | www.久久伊人 | 亚洲少妇在线 | 国产精品jizz在线观看老狼 | 不卡的一区二区 | 91看篇| 日韩成人午夜电影 | 日本天堂在线视频 | 成 人 免费 黄 色 | 九九av | 日韩精品午夜 | 日韩成人综合 | www日本黄色 | 91在线短视频 | 国色天香网站 | 在线不卡毛片 | 三级在线免费 | 天天干,天天操 | 欧美色久| 国产三级小视频 | 久草视频在线免费 | 国产精品探花一区二区三区 | av片在线免费看 | 日韩av线 | 特黄特色大片bbbb | 国产免费福利视频 | 国产情侣在线视频 | 国产一区二区在线播放 | 不卡视频免费在线观看 | 国产女教师一区二区三区 | 夜夜操狠狠干 | 欧美大色网 | 伊人最新网址 | 精品免费看 | 日韩黄片一区二区 | 九九热av| 青青草在线视频免费观看 | 国产伊人自拍 | 成人免费xxxxx在线观看 | 樱桃国产成人精品视频 | 白浆影院 | 少妇无码一区二区三区 | 色亚洲影院 | 亚洲综合涩 | 国产主播在线一区 | 偷偷在线观看免费高清av | 东凛在线观看 | 日韩国产精品一区 | 亚洲综合免费观看高清完整版在线 | 538精品一线| 国产成人一区二区三区影院在线 | 亚洲精品一区二区三区影院忠贞 | 久久精品国产99 | 亚洲爽爽网 | 日韩人妻无码一区二区三区 | 草草福利影院 | 午夜影院久久久 | 琪琪午夜伦理影院7777 | 囯产精品久久久久久 | aa在线| 91精彩刺激对白 | 久久一区二区三区四区 | 国产精品一区二区免费 | 国产精品一区二区在线播放 | 国产精品久久久久久影视 | 日韩在线视频你懂的 | 日韩一区二区毛片 | 成人免费va视频 | 女人av| 亚洲影院中文字幕 | 狠狠人妻久久久久久 | 污片在线免费看 |