题面

题解

图上的期望大部分是\(dp\),无向图的期望大部分是高斯消元

设\(f[i]\)表示走到点\(i\)的期望,\(d[i]\)表示\(i\)的度,\(to(i)\)表示\(i\)能到达的点集

所以\(f[i] = \sum\limits_{x \in to(i)} f[x] / d[x]\)

然后每个点能够列出这样的方程,直接高斯消元就可以了

代码

#include<bits/stdc++.h>
#define RG register
#define clear(x, y) memset(x, y, sizeof(x));
using namespace std; inline int read()
{
int data = 0, w = 1;
char ch = getchar();
while(ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if(ch == '-') w = -1, ch = getchar();
while(ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
return data*w;
} const int maxn(510), maxm(250100);
struct edge { int next, to; } e[maxm << 1];
int head[maxn], e_num;
inline void add_edge(int from, int to) { e[++e_num] = {head[from], to}; head[from] = e_num; }
double a[maxn][maxn], ans[maxm], Ans, deg[maxn];
int n, m, from[maxm], to[maxm]; inline void Gauss()
{
for(RG int i = 1, k = i; i <= n; i++, k = i)
{
for(RG int j = k + 1; j <= n; j++) if(fabs(a[k][i]) < fabs(a[j][i])) k = j;
swap(a[i], a[k]);
for(RG int j = i + 1; j <= n + 1; j++) a[i][j] /= a[i][i];
a[i][i] = 1.;
for(RG int j = 1; j <= n; j++)
{
if(i == j) continue;
for(RG int k = i + 1; k <= n + 1; k++) a[j][k] -= a[j][i] * a[i][k];
a[j][i] = 0.;
}
}
} int main()
{
n = read(); m = read();
for(RG int i = 1; i <= m; i++)
{
from[i] = read(); to[i] = read();
add_edge(from[i], to[i]); deg[from[i]] += 1.;
add_edge(to[i], from[i]); deg[to[i]] += 1.;
}
for(RG int i = 1; i < n; i++)
{
for(RG int j = head[i]; j; j = e[j].next) if(e[j].to != n) a[i][e[j].to] += -1. / deg[e[j].to];
a[i][i] = 1;
}
a[n][n] = 1;
a[1][n + 1] = 1; Gauss();
for(RG int i = 1; i <= m; i++)
ans[i] = ((from[i] == n) ? 0 : a[from[i]][n + 1] / deg[from[i]]) + ((to[i] == n) ? 0 : a[to[i]][n + 1] / deg[to[i]]);
sort(ans + 1, ans + m + 1);
for(RG int i = 1; i <= m; i++) Ans += (m - i + 1) * ans[i];
printf("%.3lf\n", Ans);
return 0;
}

最新文章

  1. React反模式 —— 如何不使用JSX地动态显示组件
  2. GoogleMap和高德地图最新的瓦片图地址是用什么加密或者压缩
  3. Java日志框架:SLF4J,Common-Logging,Log4J,Logback说明
  4. 在Kibana上格式化字段,更好的在dashboard上展示
  5. Android笔记——什么是json?json如何使用?
  6. Underscore学习笔记1
  7. 1^b+2^b+3^b+...+n^b数列
  8. Fedora20 和ubuntu 14.04 chrome标签中文乱码
  9. [IoC容器Unity] :Unity预览
  10. 输入整数n(n&lt;=10000),表示接下来将会输入n个实数,将这n个实数存入数组a中。请定义一个数组拷贝函数将数组a中的n个数拷贝到数组b中。
  11. 3212: Pku3468 A Simple Problem with Integers
  12. 浅论Javascript在汽车信号测试中的应用
  13. [学习OpenCV攻略][012][读取、修改、保存图像]
  14. Struts2实现文件下载
  15. RHEL64 缺少ISO 9660图像 安装程序试图挂载映像#1,在硬盘上无法找到该映像
  16. 服务器变更IP地址后SSH链接失败的解决办法
  17. linux 硬链接 软链接
  18. Vue、Vuex+Cookie 实现自动登陆 。
  19. timescaledb 集成 madlib
  20. Python如何利用Xpath进行解析

热门文章

  1. MySQL-&gt;&gt;innodb_autoinc_lock_mode参数控制auto_increment 插入数据时相关锁的模式
  2. MySQL字符存储:charset-unicode-sets
  3. [翻译] FBNetworkReachability
  4. 工作总结 [all]
  5. 搭建企业级NFS网络文件共享服务[二]
  6. [原创]获取JS数组最大值、最小值
  7. 虚拟机上的Linux Java开发环境部署记录(VirtualBox+Ubuntu)第一章-基础环境搭建
  8. Python成员运算符
  9. HDFS下载数据机制的底层分析
  10. jQuery 3D圆盘旋转焦点图 支持鼠标滚轮