博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Random Access Iterator
阅读量:4477 次
发布时间:2019-06-08

本文共 2497 字,大约阅读时间需要 8 分钟。

Recently Kumiko learns to use containers in C++ standard template library.

She likes to use the std::vector very much. It is very convenient for her to do operations like an ordinary array. However, she is concerned about the random-access iterator use in the std::vector. She misunderstanding its meaning as that a vector will return an element with equal probability in this container when she access some element in it.

As a result, she failed to solve the following problem. Can you help her?

You are given a tree consisting of nn vertices, and 11 is the root of this tree. You are asked to calculate the height of it.

The height of a tree is defined as the maximum number of vertices on a path from the root to a leaf.

Kumiko's code is like the following pseudo code.

She calls this function dfs(1, 1), and outputs the maximum value of depth array.

Obviously, her answer is not necessarily correct. Now, she hopes you analyze the result of her code.

Specifically, you need to tell Kumiko the probability that her code outputs the correct result.

To avoid precision problem, you need to output the answer modulo 10^9 + 7109+7.

Input

The first line contains an integer nn - the number of vertices in the tree (2 \le n \le 10^6)(2n106).

Each of the next n - 1n1 lines describes an edge of the tree. Edge ii is denoted by two integers u_iui and v_ivi, the indices of vertices it connects (1 \le u_i, v_i \le n, u_i \cancel= v_i)(1ui,vin,ui=vi).

It is guaranteed that the given edges form a tree.

Output

Print one integer denotes the answer.

样例输入复制

51 21 33 43 5

样例输出复制

750000006

样例解释

Kumiko's code has \frac{3}{4}43 probability to output the correct answer.

#include 
using namespace std;typedef long long ll;const int maxn = 3e6 + 10;const ll mod=1e9+7;int n;vector
e[maxn];int dep[maxn], max_depth;ll dp[maxn];inline void init(int cur, int fa) { for (register int i = 0; i < e[cur].size(); ++i) { int to = e[cur][i]; if(to==fa)continue; dep[to] = dep[cur] + 1; max_depth = max(max_depth, dep[to]); init(to, cur); }}inline ll fast_pow(ll a,ll b){ ll res=1; while(b){ if(b&1)res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res;}inline void solve(int cur, int fa) { bool flag = false; int tot=e[cur].size(); if(cur!=1)--tot; int probability=fast_pow(tot,mod-2); int sum=0; for(register int i=0;i

 

转载于:https://www.cnblogs.com/czy-power/p/11482677.html

你可能感兴趣的文章
【原创】StreamInsight查询系列(七)——基本查询操作之基础排序
查看>>
C# 安装包制作
查看>>
【P2564】生日礼物(单调队列)
查看>>
Instuments工具
查看>>
新创建django项目,但网页打不开127.0.0.1:8000
查看>>
Python练习-内置函数的应用
查看>>
洛谷P3905 道路重建
查看>>
数据表格 - DataGrid - 行编辑
查看>>
HQL查询语句
查看>>
jsp听课笔记(四)
查看>>
vim
查看>>
数组的键/值操作函数
查看>>
Android单点触控与多点触控切换的问题解决方案
查看>>
JS常用函数与方法
查看>>
SpringBoot配置devtools实现热部署
查看>>
十、Shell基础
查看>>
py16 面向对象深入
查看>>
CSS中的overflow属性
查看>>
JavaWeb学习总结第三篇--走进JSP页面元素
查看>>
Scala-Unit-1-概述及安装
查看>>