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. linux安装ssh服务

    1.安装openssh-server sudo apt-get install openssh-server 2.检查openssh-server是否安装成功 sudo ps -e | grep ss ...

  2. git fetch 更新远程代码到本地仓库

    理解 fetch 的关键, 是理解 FETCH_HEAD,FETCH_HEAD指的是: 某个branch在服务器上的最新状态’.这个列表保存在 .Git/FETCH_HEAD 文件中, 其中每一行对应 ...

  3. Kafka-Flume-elasticsearch

    a1.sources = kafkaSource a1.channels = memoryChannel a1.sinks = elasticsearch a1.sources.kafkaSource ...

  4. springMVC中@RequestParam和@RequestBody的作用

    @RequestParam和@RequestBody是什么区别,估计很多人还是不太清楚, 因为一般用@ RequestParam就足够传入参数了,要说他们区别,就需要知道contentType是什么? ...

  5. Springmvc架构

    框架结构如下图: 架构流程: 1.用户发送请求至前端控制器DispatcherServlet 2.DispatcherServlet收到请求调用HandlerMapping处理器映射器. 3.处理器映 ...

  6. Linux中,去掉终端显示的当前目录的绝对路径

    Linux中,去掉终端显示的当前目录的绝对路径 去~/.bashrc中,找到PS1变量的定义,如果没有,手动加上: 可以将显示输出到标题栏上: #export PS1="[e]2;u@H w ...

  7. DataSet 取值,DataSet行数,DataSet列数 从DataSet中取出特定值

    1 DataSet.Table[0].Rows[ i ][ j ] 其中i 代表第 i 行数, j 代表第 j 列数 2 DataSet.Table[0].Rows[ i ].ItemArray[ j ...

  8. php重定向http请求

    302  临时重定向 301  永久重定向     (  302 和 301  的区别主要在于搜索引擎,搜索引擎一般不会抓取临时重定向的页面  ) 301 和302 适用于 普通的GET 请求: 如果 ...

  9. Jenkins+PowerShell持续集成环境搭建(一)前期准备

    0. 系统要求 Windows Server:本文章使用的为Windows Server 2012 JDK:本文章使用为JDK 1.8 Windows PowerShell:本文章使用为PowerSh ...

  10. hdu 4578 Transformation 线段树多种操作裸题

    自己写了一个带结构体的WA了7.8次 但是测了几组小数据都对..感觉问题应该出在模运算那里.写完这波题解去对拍一下. 以后线段树绝不写struct!一般的struct都带上l,r 但是一条线段的长度确 ...