CF235D Graph Game
好题
树?
考虑每个点被计算多少次
但是和当前分治中心有关系的(相当于我们把这次访问,归到这次的中心上去)
所以,f(a,b),对于a作为中心时候,和b相连的概率
也就是两者必然分离,最后一次连在一起的时候,是否能够恰好选择a
贡献:1/(dis(x,y))
基环树?
考虑:
a,b最后一起之前断的边,在所有可能情况中,关心(a-y-b)先断的是哪一个,概率1/(x+y),(a-z-b) 先断哪一个1/(x+z)
但是还有一种合法情况:直接断x,别的都不动。两者中会算重,减去1/(x+y+z)
所以,1/(x+y)+1/(x+z)-1/(x+y+z)
(条件概率也可以推式子证明,通分后得到同样结果)
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define ld double
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
char ch;x=;bool fl=false;
while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);
(fl==true)&&(x=-x);
}
template<class T>il void output(T x){if(x/)output(x/);putchar(x%+'');}
template<class T>il void ot(T x){if(x<) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');} namespace Miracle{
const int N=;
int n;
struct node{
int nxt,to;
}e[*N];
int hd[N],cnt;
void add(int x,int y){
e[++cnt].nxt=hd[x];
e[cnt].to=y;
hd[x]=cnt;
}
int sta[N],top;
bool vis[N];
bool fl;
int on[N],mem[N],num;
void fin(int x,int fa){
sta[++top]=x;vis[x]=;
// cout<<" xx "<<x<<" fa "<<fa<<endl;
for(reg i=hd[x];i;i=e[i].nxt){
int y=e[i].to;
if(y==fa) continue;
if(vis[y]){
if(!fl){
fl=true;
int z;
do{
z=sta[top--];
mem[++num]=z;on[z]=num;
}while(z!=y);
}
}
else fin(y,x);
}
if(sta[top]==x) sta[top--]=;
}
int be[N];
int dis[N];
void dfs(int x,int fa,int rt){
be[x]=rt;
for(reg i=hd[x];i;i=e[i].nxt){
int y=e[i].to;
if(y==fa) continue;
if(on[y]) continue;
dis[y]=dis[x]+;
dfs(y,x,rt);
}
}
double ans;
int rt;
void sol(int x,int d){
// cout<<" x "<<x<<" "<<d;//" fa "<<fa<<" "<<d<<endl;
vis[x]=;
if(x!=rt){
if(be[x]==be[rt]){
ans+=(ld)1.0/(( double)d);
}else{
int a=dis[rt]+dis[x],b=abs(on[be[x]]-on[be[rt]])-,c=num--b;
ans+=(ld)1.0/((ld)a+b)+(ld)1.0/((ld)a+c)-(ld)1.0/((ld)a+b+c);
}
}
for(reg i=hd[x];i;i=e[i].nxt){
int y=e[i].to;
if(vis[y]) continue;
sol(y,d+);
}
}
int main(){
rd(n);int x,y;
for(reg i=;i<=n;++i){
rd(x);rd(y);
++x;++y;
add(x,y);add(y,x);
}
fin(,);
for(reg i=;i<=num;++i){
dis[mem[i]]=;
dfs(mem[i],,mem[i]);
}
// cout<<"after dfs "<<endl;
for(reg i=;i<=n;++i){
memset(vis,,sizeof vis);
rt=i;sol(i,);
}
ans+=n;
printf("%.10lf",ans);
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
Date: 2019/3/29 19:42:26
*/
CF235D Graph Game的更多相关文章
- [开发笔记] Graph Databases on developing
TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...
- Introduction to graph theory 图论/脑网络基础
Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...
- POJ 2125 Destroying the Graph 二分图最小点权覆盖
Destroying The Graph Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8198 Accepted: 2 ...
- [LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- [LeetCode] Graph Valid Tree 图验证树
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- [LeetCode] Clone Graph 无向图的复制
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...
- 讲座:Influence maximization on big social graph
Influence maximization on big social graph Fanju PPT链接: social influence booming of online social ne ...
- zabbix利用api批量添加item,并且批量配置添加graph
关于zabbix的API见,zabbixAPI 1item批量添加 我是根据我这边的具体情况来做的,本来想在模板里面添加item,但是看了看API不支持,只是支持在host里面添加,所以我先在一个ho ...
- Theano Graph Structure
Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...
随机推荐
- bnu——GCD SUM (莫比乌斯反演)
题目:GCD SUM 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=39872 算法:莫比乌斯反演.优化 #include<stdio.h& ...
- socket基础编程-1
server端和client端 1.server端: import socket server=socket.socket() server.bind(('localhost',8080)) serv ...
- k8s容器的资源限制
1.k8s支持内存和cpu的限制 requests:容器运行需求,最低保障limits:限制,硬限制(资源上限) CPU: 1颗逻辑CPU(1核CPU=4个逻辑CPU) 1物理核=1000个微核(mi ...
- django migrate报错(提前删除表等)
python3 manage.py makemigrations python3 manage.py migrate ##报错 改为##更改migrates的状态 python3 manage.py ...
- @Autowired 与@Resource的区别(详细)
参考:@Autowired 与@Resource的区别(详细) spring不但支持自己定义的@Autowired注解,还支持几个由JSR-250规范定义的注解,它们分别是@Resource.@Pos ...
- 老男孩python学习自修第十四天【序列化和json】
序列化是使用二进制的方式加密列表,字典或集合,反序列化是解密的过程:序列化开启了两个独立进程进行数据交互的通路 使用pickle进行序列化和反序列化 例如: pickle_test.py #!/usr ...
- windows 安装tensorflow
原文知乎:https://zhuanlan.zhihu.com/p/25778703 前言 看到Rstudio中开始支持Tensorflow,本人是欣喜若狂的,同时TensorFlow官网从16年9月 ...
- Monkey脚本API简介
一.API简介 LaunchActivity(pkg_name, cl_name):启动应用的Activity.参数:包名和启动的Activity. Tap(x, y, tapDuration): 模 ...
- LVS (Linux Virtual Server) 负载均衡
[大型网站技术实践]初级篇:借助LVS+Keepalived实现负载均衡 一.负载均衡:必不可少的基础手段 1.1 找更多的牛来拉车吧 当前大多数的互联网系统都使用了服务器集群技术,集群即将相同服 ...
- Spring 使用介绍(九)—— 零配置(二)
三.Bean定义 1.开启bean定义注解支持 开启注解支持须添加以下配置项: <context:component-scan base-package="cn.matt"/ ...