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 ...
随机推荐
- Java中List集合去除重复数据的四种方法
1. 循环list中的所有元素然后删除重复 public static List removeDuplicate(List list) { for ( int i = 0 ; i < lis ...
- java学习之—并归排序
/** * 并归排序 * Create by Administrator * 2018/6/26 0026 * 下午 5:13 **/ public class DArray { private lo ...
- PDO访问Mysql数据库
$dsn = 'mysql:host=127.0.0.1;dbname=myblog'; $username = 'root'; $pwd = '; $pdo = new PDO($dsn,$user ...
- Spring Boot 构建电商基础秒杀项目 (九) 商品列表 & 详情
SpringBoot构建电商基础秒杀项目 学习笔记 ItemDOMapper.xml 添加 <select id="listItem" resultMap="Bas ...
- yolo算法解析
- Cmder使用ls中文显示乱码解决方案
操作系统:Windows 7 旗舰版 Cmder:1.3.2 默认配置不支持使用ls显示中文命名的文件列表. 解决方法: 按下Win+Alt+P打开设置. 在StartUp - Environment ...
- BZOJ3277 串 【后缀数组】【二分答案】【主席树】
题目分析: 用"$"连接后缀数组,然后做一个主席树求区间内不同的数的个数.二分一个前缀长度再在主席树上求不同的数的个数. 代码: #include<bits/stdc++.h ...
- AHOI2013 差异 【后缀数组】
题目分析: 求出height以后很明显跨越最小height的一定贡献是最小height,所以对于区间找出最小height再将区间对半分. 代码: #include<bits/stdc++.h&g ...
- Spring模块介绍
GroupId ArtifactId 说明 org.springframework spring-beans Beans 支持,包含 Groovy org.springframework spring ...
- 【BZOJ1565】【NOI2009】植物大战僵尸 网络流 最大权闭合子图
题目大意 给你一个\(n\times m\)的地图,每个格子上都有一颗植物,有的植物能保护其他植物.僵尸从右往左进攻,每吃掉一颗植物就可以得到\(a_{i,j}\)的收益(\(a_{i,j}\)可 ...