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 硬件和系统配置查看命令小结

    https://blog.csdn.net/strongwangjiawei/article/details/8208825 转帖了不少 发现自己记住的还是不多.. Linux 硬件和系统配置查看命令 ...

  2. Linux 下面 Sqlserver 2017 的简单安装

    1. 公司网络太烂 yum 在线安装失败 2. 解决方法 找微软的官网 百度网盘 离线下载rpm包. https://packages.microsoft.com/rhel/7/mssql-serve ...

  3. 1228.Poor Pigs 可怜的猪

    转自[LeetCode] Poor Pigs 可怜的猪 There are 1000 buckets, one and only one of them contains poison, the re ...

  4. Spark join连接

    内链接

  5. python之路--第一类对象,函数名,变量名

    一 . 第一类对象 函数对象可以像变量一样进行赋值 , 还可以作为列表的元素进行使用 可以作为返回值返回 , 可以作为参数进行传递 def func(): def people(): print('金 ...

  6. Java多线程之Join方法阻塞线程

    package org.study2.javabase.ThreadsDemo.status; /** * @Auther:GongXingRui * @Date:2018/9/19 * @Descr ...

  7. 转载:实现MATLAB2016a和M文件关联

    转载自http://blog.csdn.net/qq_22186119 新安装MATLAB2016a之后,发现MATLAB没有和m文件关联 每次打开m文件后都会重新打开一次MATLAB主程序 后来发现 ...

  8. c提取文件路径、文件名和后缀名

    /* MAKEPATH.C */ #include <stdlib.h> #include <stdio.h> void main( void ) { char path_bu ...

  9. Mysql 查看连接数,状态 最大并发数(赞)

    Mysql 查看连接数,状态 最大并发数(赞)   -- show variables like '%max_connections%'; 查看最大连接数 set global max_connect ...

  10. MySql获取树型结构的所有子节点

    stackoverflow的解决方案,亲测有效: SELECT * FROM person WHERE department IN (SELECT department_id FROM departm ...