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

  1. [开发笔记] Graph Databases on developing

    TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...

  2. Introduction to graph theory 图论/脑网络基础

    Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...

  3. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  4. [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), ...

  5. [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), ...

  6. [LeetCode] Clone Graph 无向图的复制

    Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...

  7. 讲座:Influence maximization on big social graph

    Influence maximization on big social graph Fanju PPT链接: social influence booming of online social ne ...

  8. zabbix利用api批量添加item,并且批量配置添加graph

    关于zabbix的API见,zabbixAPI 1item批量添加 我是根据我这边的具体情况来做的,本来想在模板里面添加item,但是看了看API不支持,只是支持在host里面添加,所以我先在一个ho ...

  9. Theano Graph Structure

    Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...

随机推荐

  1. sass变量引入全局

    https://www.jianshu.com/p/ab9ab999344b(copy) 本文以Sass做案例,Less的参考,基本配置大同小异. 假如我们有一个Sass的全局变量common.scs ...

  2. 在linux上安装Scala详细步骤

    scala在linux安装很简单,就是下载,解压,配置环境变量,source一下成功. 提君博客原创 >>提君博客原创 http://www.cnblogs.com/tijun/ < ...

  3. 利用Python制作简单的小程序:IP查看器

    前言 说实话,查看电脑的IP,也挺无聊的,但是够简单,所以就从这里开始吧.IP地址在操作系统里就可以直接查看.但是除了IP地址,我们也想通过IP获取地理地址和网络运营商情况.IP地址和地理地址并没有固 ...

  4. vue中组件绑定事件时是否加.native

    组件绑定事件时 1. 普通组件绑定事件不能添加.native, 添加后事件失效 2. 自定义组件绑定事件需要添加.native, 否则事件无效 <template> <!-- < ...

  5. Spring Boot 构建电商基础秒杀项目 (二) 使用 Spring MVC 方式获取用户信息

    SpringBoot构建电商基础秒杀项目 学习笔记 修改 DOMapper 在 UserPasswordDOMapper.xml 添加: <select id="selectByUse ...

  6. React 学习(三) ---- state 和 事件处理函数

    在上两节中,我们讲述了props, 组件使用props进行渲染,但是这是一次性的, props渲染完成之后就不做任何事情了,但是现实中却不是这样的,当我们点击购物车上的加减按钮时,数量会自动加1或减1 ...

  7. hdu-2717(基础搜索bfs)

    题意:给你n和k,问你n最少花费多少代价能得到k: 有两种变换:1.n++或者n--: 2.n=n*2: 两种代价每次的花费都是1: 思路:一维的bfs,每次入队三个点,一个是n+1,一个是n-1,一 ...

  8. hdu1875(最小生成树prime)

    思路:一开始想用贪心来着,发现贪心有缺陷,然后就用了最小生成树来写,这里用了prime算法,首先,先建个图,两点之间的边的权值就是两个点的距离,然后直接prime模板 代码 #include<i ...

  9. BZOJ5475 WC2019数树(prufer+容斥原理+树形dp+多项式exp)

    因为一大堆式子实在懒得写题解了.首先用prufer推出CF917D用到的结论,然后具体见前言不搭后语的注释. #include<iostream> #include<cstdio&g ...

  10. 网页调起QQ聊天

    将QQ账号换成正常的QQ号即可,要确保这个QQ支持临时会话 <a href="http://wpa.qq.com/msgrd?v=3&uin=QQ账号&site=qq& ...