1934

水题 RE了N久  后来发现是无向图

 #include <iostream>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cstdio>
#include<queue>
using namespace std;
#define N 2000010
#define INF 0xfffffff
struct node
{
int u,v,next;
double w;
}ed[N<<];
int t,head[N],vis[N],dis[N],pa[N],o[N];
double p[N];
int n,m;
void init()
{
t = ;
memset(head,-,sizeof(head));
}
void add(int u,int v,int w)
{
ed[t].u = u;
ed[t].v = v;
ed[t].w = w;
ed[t].next = head[u];
head[u] = t++;
}
void spfa(int s,int e)
{
memset(vis,,sizeof(vis));
int i;
for(i = ; i <= n ; i++)
{
dis[i] = INF;
p[i] = ;
}
queue<int>q;
dis[s] = ;
p[s] = ;
q.push(s);
while(!q.empty())
{
int u = q.front();
q.pop();
vis[u] = ;
for(i = head[u] ; i != - ; i = ed[i].next)
{
int v = ed[i].v;
double w = ed[i].w;
if(dis[v]>=dis[u]+)
{
if(dis[v]==dis[u]+)
{
if(p[v]<p[u]*w/100.0)
{
p[v] = p[u]*w/100.0;
pa[v] = u;
}
}
else
{
dis[v] = dis[u]+;
p[v] = p[u]*w/100.0;
pa[v] = u;
}
if(!vis[v])
{
vis[v] = ;
q.push(v);
}
}
}
}
printf("%d %lf\n",dis[e],-p[e]);
int x = pa[e],g=;
o[g] = e;
while(x!=s)
{
g++;
o[g] = x;
x = pa[x];
}
g++;
o[g] = s;
for(i = g ; i > ; i--)
printf("%d ",o[i]);
printf("%d\n",o[]);
}
int main()
{
int i;init();
int a,b;
scanf("%d%d",&n,&m);
scanf("%d%d",&a,&b);
for(i = ; i <= m ; i++)
{
int u,v;
double w;
scanf("%d%d%lf",&u,&v,&w);
add(u,v,-w);
add(v,u,-w);
}
spfa(a,b);
return ;
}

最新文章

  1. beego上传文件
  2. ios中文转码的一个奇葩问题
  3. 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法
  4. Unix网络编程 -- ubuntu下搭建编译环境( 解决unp.h 编译等问题)
  5. [lua]lua简介
  6. CSS3中新出现的技术
  7. hadoop2 作业执行过程之reduce过程
  8. Nginx源码研究三:Epoll在NGINX中的使用
  9. 封装的localstorge的插件,store.js
  10. [国嵌攻略][048][MMU配置与使用]
  11. Linuxc - 执行c程序
  12. VueJs(2)---VueJs开发环境的搭建和讲解index.html如何被渲染
  13. C#2.0之细说泛型
  14. (摘)Entity Framework Core 2.1带来更好的SQL语句生成方案
  15. jQuery.prop , jQuery.attr ,jQuery.data
  16. php 接口与前端数据交互实现
  17. Codeforces 982E Billiard exgcd
  18. 转: linux centos7 下安装maven
  19. c# 使用checked和unchecked
  20. VB.NET中lambda的写法

热门文章

  1. NGUI基础之button(按钮)
  2. SlimDx绘制点图元的问题
  3. Liferay SDK 6.2与7.0中build.[$username].properties 文件的配置
  4. FlashBuilder 4.7 破解方法
  5. 不用安装语言包,教你将PS界面语言修改成默认语言(英语)
  6. IntelliJ IDEA 14 利用JRebel实现热部署 二
  7. Java7 新特性 数值文本表示法
  8. catci监控
  9. MATLAB三维散点图的绘制(scatter3、plot3)
  10. C++中的mutable关键字