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. c# 多线程创建 ---简单

    Thread t = new Thread(new ParameterizedThreadStart(UploadCard)); t.IsBackground = false;//后台线程  前台线程 ...

  2. namenode 和datanode无法启动,错误:FSNamesystem initialization failed. datanode.DataNode: Incompatible namespaceIDs

    问题一: namenode无法启动,查看日志,错误信息如下: org.apache.hadoop.hdfs.server.namenode.FSNamesystem: FSNamesystem ini ...

  3. poj1181 大数分解

    //Accepted 164 KB 422 ms //类似poj2429 大数分解 #include <cstdio> #include <cstring> #include ...

  4. 2016-1-15 抽屉效果实现demo

    // // ViewController.m // 抽屉 // // Created by Mac on 16/1/15. // Copyright © 2016年 Mac. All rights r ...

  5. oracle的存储结构

    表空间 当一个用户被创建以后,随之就要为用户分配数据存储的空间,这在oracle中成为“表空间”(Tablespace). 在数据库中创建用户时,基于应用性能和管理的考虑,最好为不同的用户创建独立的表 ...

  6. 使用busybox构建根文件系统

    当我们在Qemu上运行起来自己编译的内核之后,需要使用busybox构建一个文件系统,将此文件系统挂载上去就可以使用busybox提供的各种命令了. 1.编译安装busybox 源码下载地址:http ...

  7. HDOJ-三部曲一(搜索、数学)-1006- Catch That Cow

    Catch That Cow Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Tot ...

  8. UVA1476 三分法

    单峰函数(即先递增后递减,有极大值的函数),都可以用三分法来求 #include <iostream> #include <cmath> #include <cstdio ...

  9. iOS应用中通过设置VOIP模式实现休眠状态下socket的长连接

    如果你的应用程序需要在设备休眠的时候还能够收到服务器端发送的消息,那我们就可以借助VOIP的模式来实现这一需求.但是如果的应用程序并不是正真的VOIP应用,那当你把你的应用提交到AppStore的时候 ...

  10. Unity3D ShaderLab 基础的高光实现

    Unity3D ShaderLab 基础的高光实现 关于高光: 在一个物体表面的高光属性就是为了描述它是如何表现光泽.这种类型的效果在着色器的世界中通常称为视点相关效果. 之所以这样说,是因为为了实现 ...