题目链接

大致题意:从根节点出发,在节点x有son[x]次等概率进入儿子节点,求到达最深深度的概率。son[x]为x节点的儿子节点个数。

又又又又没做出来,心态崩了。

下来看了官方题解后发觉自己大体思路是没错的,但是细节太弱了Orz。

大体思路:设dp[x]为以x为根节点,求到达最深深度的概率。先跑一遍dfs,求出每个点的子节点数,每个点的深度以及最深深度。

我们可以求得从x点一次不能到达最深深度的概率为$cnt =1-(\tfrac{\sum_{y\epsilon x } dp[y]}{son[x]})$

则$dp[x]=1-cnt^{son[x]}$为son[x]次能到达最深深度的概率。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e6 + ;
const ll mod = 1e9 + ;
struct node {
int s, e, next;
}edge[maxn];
int head[maxn], len;
void init() {
memset(head, -, sizeof(head));
len = ;
}
void add(int s, int e) {
edge[len].e = e;
edge[len].next = head[s];
head[s] = len++;
}
int mxd[maxn], d[maxn], son[maxn];
ll dp[maxn];
ll qpow(ll a, ll b, ll mod) {
ll ans = ;
while (b) {
if (b & )ans = ans * a % mod;
a = a * a % mod;
b >>= ;
}
return ans;
}
void dfs(int x, int fa) {
mxd[x] = d[x];
for (int i = head[x]; i != -; i = edge[i].next) {
int y = edge[i].e;
if (y == fa)continue;
d[y] = d[x] + ;
son[x]++;
dfs(y, x);
mxd[x] = max(mxd[x], mxd[y]);
}
}
void dfs1(int x, int fa) {
ll sum = ;
for (int i = head[x]; i != -; i = edge[i].next) {
int y = edge[i].e;
if (y == fa)continue;
if (mxd[y] == mxd[]) {
dfs1(y, x);
sum = (sum + dp[y]) % mod;
}
}
if (son[x] == )
dp[x] = ;
else {
ll p = sum * qpow(son[x], mod - , mod) % mod;
p = ( - p + mod) % mod;
dp[x] = ( - qpow(p, son[x], mod) + mod) % mod;
}
}
int main() {
int n;
scanf("%d", &n);
init();
for (int i = ; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
add(x, y), add(y, x);
}
dfs(, );
dfs1(, );
printf("%lld\n", dp[]);
}

[2019徐州网络赛J题]Random Access Iterator的更多相关文章

  1. The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 K题 center

    You are given a point set with nn points on the 2D-plane, your task is to find the smallest number o ...

  2. [2019上海网络赛J题]Stone game

    题目链接 CSLnb! 题意是求出给定集合中有多少个合法子集,合法子集的定义为,子集和>=总和-子集和$\& \&$子集和-(子集的子集和)<=总和-子集和. 其实就是很简 ...

  3. ICPC 2019 徐州网络赛

    ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...

  4. ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval

    ACM-ICPC 2019南昌网络赛I题 Yukino With Subinterval 题目大意:给一个长度为n,值域为[1, n]的序列{a},要求支持m次操作: 单点修改 1 pos val 询 ...

  5. 2019徐州网络赛 I J M

    I. query 比赛时候没有预处理因子疯狂t,其实预处理出来因子是\(O(nlog(n))\)级别的 每个数和他的因子是一对偏序关系,因此询问转化为(l,r)区间每个数的因子在区间(l,r)的个数 ...

  6. ACM-ICPC 2019南昌网络赛F题 Megumi With String

    ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...

  7. luogu 1327 数列排序 & 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J题 循环节

    luogu 1327 数列排序 题意 给定一个数列\(\{an\}\),这个数列满足\(ai≠aj(i≠j)\),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? ...

  8. 2017乌鲁木齐网络赛 j 题

    题目连接 : https://nanti.jisuanke.com/t/A1256 Life is a journey, and the road we travel has twists and t ...

  9. query 2019徐州网络赛(树状数组)

    query \[ Time Limit: 2000 ms \quad Memory Limit: 262144 kB \] 题意 补题才发现比赛的时候读了一个假题意.... 给出长度为 \(n\) 的 ...

随机推荐

  1. springCloud——Eureka、Ribbon理解

    一. 服务注册中心.服务提供者.服务消费者 如何通信? 客户端: 应用主类中配置@EnableDiscoveryClient application.properties中配置defaultZone指 ...

  2. jvm——metaspace代替永久代

    https://mp.weixin.qq.com/s?__biz=MzIzNjI1ODc2OA==&mid=2650886860&idx=1&sn=f8bc6ab03d7a07 ...

  3. ASP.NET大文件断点上传

    HTML部分 <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="index.aspx. ...

  4. T3

    T3构造图

  5. The GuidRepresentation for the reader is CSharpLegacy, which requires the binary sub type to be Uuid

    使用客户端链接MongoDb报错 The GuidRepresentation for the reader is CSharpLegacy, which requires the binary su ...

  6. HDU 6651 Final Exam

    hdu题面 Time limit 2000 ms Memory limit 524288 kB OS Windows 吐槽 比赛时候晕死了-- 解题思路 先留坑 公式法 https://blog.cs ...

  7. latex beamer技巧

    %章节标题\section{Related work(LSH)} %开始一页ppt \begin{frame}{Related work}{} \partitle{Locality-Sensitive ...

  8. Python模块之-OS模块

    一.os模块概述 Python os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.(一语中的) 二.常用方法 1.os.name 输出字符串指示正在使用的平台 ...

  9. Linux安装vsftpd及配置详解

    1 安装vsftpd组件 安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件.[root@bogon ~]# yum -y install vsftpd 2.FT ...

  10. sqli-labs(19)

    百度了一下 基于错误的referer头的注入 0X01爱之初体验 猜测是基于referer头的注入 我们在referer后面加入单引号测试一下 真的报错了诶 那我们猜测一下 他应该是把 referer ...