因为边权为1所以a直接bfs瞎搞就行……我一开始竟然写了个spfa

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
const int N=1005,inf=1e9;
int n,m,st,ed,h[N],cnt,a[N][N],b[N][N],dis[N][N],d[N];
double f[N][N];
bool v[N][N];
struct qwe
{
int ne,to;
}e[N<<1];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
void add(int u,int v)
{
cnt++;
e[cnt].ne=h[u];
e[cnt].to=v;
h[u]=cnt;
}
double dfs(int u,int v)
{
if(f[u][v]>=-1)
return f[u][v];
if(u==v)
return f[u][v]=0;
if(dis[u][v]<=2)
return f[u][v]=1;
double p=1.0/((double)d[v]+1.0);
f[u][v]=1;
for(int i=h[v];i;i=e[i].ne)
f[u][v]+=p*dfs(a[u][v],e[i].to);
f[u][v]+=p*dfs(a[u][v],v);
return f[u][v];
}
int main()
{
n=read(),m=read(),st=read(),ed=read();
for(int i=1;i<=m;i++)
{
int x=read(),y=read();
d[x]++,d[y]++;
add(x,y),add(y,x);
}
queue<int>q;
for(int s=1;s<=n;s++)
{
v[s][s]=1;
q.push(s);
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=h[u];i;i=e[i].ne)
if(!v[s][e[i].to])
{
dis[s][e[i].to]=dis[s][u]+1;
v[s][e[i].to]=1;
q.push(e[i].to);
}
}
}
for(int s=1;s<=n;s++)
for(int u=1;u<=n;u++)
{
int mn=inf,w=inf;
for(int i=h[s];i;i=e[i].ne)
if(dis[e[i].to][u]<mn||(dis[e[i].to][u]==mn&&e[i].to<w))
mn=dis[e[i].to][u],w=e[i].to;
b[s][u]=w;
}
for(int s=1;s<=n;s++)
for(int i=1;i<=n;i++)
a[s][i]=dis[s][i]<=2?i:b[b[s][i]][i];
// for(int i=1;i<=n;i++)
// {
// for(int j=1;j<=n;j++)
// cerr<<a[i][j]<<" ";
// cerr<<endl;
// }
memset(f,-1,sizeof(f));
printf("%.3f\n",dfs(st,ed));
return 0;
}

最新文章

  1. java的布尔运算符和位运算符
  2. 将数据从MySQL迁移到Oracle的注意事项
  3. 深入学习jQuery选择器系列第五篇——过滤选择器之内容选择器
  4. [POJ2069]Super Star(模拟退火)
  5. 从Microsoft.AspNet.Identity看微软推荐的一种MVC的分层架构
  6. android 透明度颜色值
  7. 【Xamarin报错】libpng warning : iCCP: Not recognizing known sRGB profile that has been edited
  8. mybatis 的&lt;![CDATA[ ]]&gt;
  9. ValueError: Attempted relative import in non-package
  10. Apache ActiveMQ消息中间件的基本使用
  11. 《SAS编程和数据挖掘商业案例》第14部分学习笔记
  12. APP生产流程图片解说
  13. 初学jQuery之jQuery事件与动画
  14. sql语句实现累计数
  15. 《JAVA程序设计与实例》记录与归纳--继承与多态
  16. css里面如何设置body背景图片满屏
  17. Docker-Dockerfile及基本语法
  18. linux 安装中文支持
  19. Eclipse 中构建 Maven 项目的完整过程 - SpringBoot 项目
  20. Sql Server中的nvarchar(n)、varchar(n) 和Mysql中的char(n)、varchar(n)

热门文章

  1. msp430项目编程03
  2. HDU 5668 Circle
  3. HashCode和equal方法
  4. Linux驱动开发:USB驱动之usb_skel分析
  5. win7右下角无线网图标显示未连接,但是实际上已连接上,也能上网
  6. Linux性能诊断工具
  7. BZOJ 1005 明明的烦恼 Prufer序列+组合数学+高精度
  8. Hadoop之中的一个:Hadoop的安装部署
  9. 我的gulp.js清单
  10. 一个程序员对微信小程序的看法