Black Spot

Time limit: 1.0 second
Memory limit: 64 MB
Bootstrap: Jones's terrible leviathan will find you and drag the Pearl back to the depths and you along with it.
Jack: Any idea when Jones might release said terrible beastie?
Bootstrap: I already told you, Jack. Your time is up. It comes now,
drawn with ravenous hunger to the man what bears the black spot.
Captain Jack Sparrow has got a black spot on his hand and
he avoids going to high seas because sea monster Kraken
is waiting there for him. But he can’t stay in his place due
to his freedom-loving nature. And now Jack is going to Tortuga.
There are n islands in the Caribbean Sea. Jack is going to reach Tortuga,
sailing from island to island by routes that allow him to be
in the high seas for a short time.
Jack knows such routes for some pairs of islands,
but they could also be dangerous for him.
There is a probability to meet Kraken on each route.
Jack is in a hurry and he wants to reach Tortuga visiting as
small number of islands as possible.
If there are several variants of such paths he wants to
choose a path with the least probability of meeting Kraken.
But Jack will be satisfied with any path with minimal number of islands if the probability
of meeting Kraken on this path differs from the minimal one in no more than 10−6
.
Help Jack find such path.

Input

The first line contains two integers n, m — the quantity of islands
and known routes between them (2 ≤ n ≤ 105; 1 ≤ m ≤ 105).
The second line contains two integers s and t —
the number of island where Jack is and the number of Tortuga (1 ≤ s, tn; st).
Each of the following m lines contains three integers —
the numbers of islands ai and bi where the route is known and pi —
probability to meet Kraken on that route as percentage (1 ≤ ai, bin; aibi; 0 ≤ pi ≤ 99).
No more than one route is known between each pair of islands.

Output

In the first line output k — number of islands along the
path and p — probability to meet Kraken on that path.
An absolute error of p should be up to 10−6.
In the next line output k integers — numbers of islands in the order of the path.
If there are several solutions, output any of them.

Sample

input output
4 4
1 3
1 2 50
2 3 50
1 4 10
4 3 10
3 0.19
1 4 3
Problem Author: Denis Dublennykh (prepared by Egor Shchelkonogov)
【分析】就是个最短路。题目要求遇见怪物的概率最小,可以求最大的遇不到怪物的概率。就是在SPFA中当距离相同时维护概率最大就行了。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = ;
const int M = ;
int n,m,cnt=;
int tot=,s,t;
int head[N],dis[N],vis[N],pre[N];
double va[N];
struct man {
int to,next;
double val;
} edg[N];
void add(int u,int v,double val) {
edg[tot].to=v;
edg[tot].val=val;
edg[tot].next=head[u];
head[u]=tot++;
edg[tot].to=u;
edg[tot].val=val;
edg[tot].next=head[v];
head[v]=tot++;
}
void spfa() {
met(dis,inf);met(vis,);
dis[s]=;
queue<int>q;
q.push(s);
vis[s]=;
va[s]=;
while(!q.empty()) {
int w=q.front();
q.pop();
vis[w]=;
for(int i=head[w]; i!=-; i=edg[i].next) {
int v=edg[i].to;//printf("###%d %d %d\n",v,dis[v],dis[w]);
if(dis[v]>dis[w]+) {
dis[v]=dis[w]+;
pre[v]=w;
va[v]=va[w]*edg[i].val;
if(!vis[v]) {
vis[v]=;
q.push(v);
}
} else if(dis[v]==dis[w]+) {
if(va[w]*edg[i].val-va[v]>) {
pre[v]=w;
va[v]=va[w]*edg[i].val;
if(!vis[v]) {
vis[v]=;
q.push(v);
}
}
}
}
}
}
int main() {
int u,v,val;
met(head,-);
scanf("%d%d",&n,&m);
scanf("%d%d",&s,&t);
while(m--) {
scanf("%d%d%d",&u,&v,&val);
double ff=val*1.0/;
add(u,v,-ff);
}
spfa();
printf("%d %.7lf\n",dis[t],-va[t]);
stack<int>p;
for(int i=t;;i=pre[i]){
p.push(i);
if(i==s)break;
}
while(!p.empty())printf("%d ",p.top()),p.pop();printf("\n");
return ;
}

URAL 1934 Black Spot(最短路)的更多相关文章

  1. URAL 1934 Black Spot --- 最短的简单修改

    右侧是1.维护的同时保持最短路p值至少,我有直接存款(1-p).该概率不满足,为了使这个值极大. #include <iostream> #include <cstdlib> ...

  2. URAL 1934 spfa算法

    D - Black Spot Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  3. URAL 1934 最短路变形

    DES:给出起点和终点.给出所有小岛的编号.所有路径的起始点.和遇到怪物的概率.要求在最短路的条件下维护遇见怪物的概率最小的路径.就是用 SPFA算法.每条路的权值设为1.最短路即为途径的岛数最少.同 ...

  4. URAL 1085 Meeting(最短路)

    Meeting Time limit: 2.0 secondMemory limit: 64 MB K friends has decided to meet in order to celebrat ...

  5. ural 1355. Bald Spot Revisited(数的素因子划分)

    1355. Bald Spot Revisited Time limit: 1.0 secondMemory limit: 64 MB A student dreamt that he walked ...

  6. URAL 2069 Hard Rock (最短路)

    题意:给定 n + m 个街道,问你从左上角走到右下角的所有路的权值最小的中的最大的. 析:我们只要考虑几种情况就好了,先走行再走列和先走列再走行差不多.要么是先横着,再竖着,要么是先横再竖再横,要么 ...

  7. 1934. Black Spot(spfa)

    1934 水题 RE了N久 后来发现是无向图 #include <iostream> #include<cstring> #include<algorithm> # ...

  8. URAL 1355. Bald Spot Revisited(数论)

    题目链接 题意 : 一个学生梦到自己在一条有很多酒吧的街上散步.他可以在每个酒吧喝一杯酒.所有的酒吧有一个正整数编号,这个人可以从n号酒吧走到编号能整除n的酒吧.现在他要从a号酒吧走到b号,请问最多能 ...

  9. Ural 1741 Communication Fiend(隐式图+虚拟节点最短路)

    1741. Communication Fiend Time limit: 1.0 second Memory limit: 64 MB Kolya has returned from a summe ...

随机推荐

  1. Android学习参考教程和工具及常见问题解决

    参考教程: 1.菜鸟教程:http://www.runoob.com/w3cnote/android-tutorial-intro.html 2.Android初學特訓班(第五版) 使用工具: 1.A ...

  2. Quartz2D

    http://donbe.blog.163.com/blog/static/138048021201052093633776/ 详解 代码如下: DJView 绘制线段 基本图形 // // DJVi ...

  3. 黑马程序员——C语言基础语法 关键字 标识符 注释 数据及数据类型

    Java培训.Android培训.iOS培训..Net培训.期待与您交流! (一下内容是对黑马苹果入学视频的个人知识点总结) (一)C语言简单介绍 (1)C语言程序是由函数组成的任何C语言程序都是由一 ...

  4. 破解Xamarin

    试用了一阵子Mono For Android,今天到期了,,囊中羞涩,只好破解. 说是要在vs2013的英文界面下运行破解包,不知道是真是假,下载并安装了一个. 然后又下载了破解包.是个名为xa.ra ...

  5. Android Studio如何发布APK

    (1)Android Studio菜单Build->Generate Signed APK (2)弹出窗口 (3)创建密钥库及密钥,创建后会自动选择刚创建的密钥库和密钥(已拥有密钥库跳过)    ...

  6. 《java中局部变量和成员变量的区别》

    class Car { String color; int number; void run() { System.out.println(color+"::"+number); ...

  7. SQL Server 按某一字段分组 取 最大 (小)值所在行的数据

    SQL Server 按某一字段分组 取 最大 (小)值所在行的数据 -- 按某一字段分组 取 最大 (小)值所在行的数据 -- (爱新觉罗.毓华(十八年风雨,守得冰山雪莲花开) 2007-10-23 ...

  8. list.clear()和list=null的区别

    以前并没有注意到list.clear()和list=null的区别,其实,区别在于 clear()方法是将list清空,但是对象的引用还在,只不过是一个表现为空引用 list=null是将list对象 ...

  9. Ubuntu安装Fcitx(小企鹅五笔输入法)

    安装配置如下: 1. 安装 fcitx sudo apt-get install fcitx 2. 配置默认输入法为 fcitx im-switch -s fcitx // 注意无须加 sudo 3. ...

  10. linux常用命令:5网络命令

    网络命令 1. 指令名称:write 指令所在路径:/usr/bin/write 执行权限:所有用户 语法:write  <用户名> 功能描述:给用户发送信息,以Ctrl+D保存结束