URAL 1934 Black Spot(最短路)
Black Spot
Memory limit: 64 MB
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.
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.
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.
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
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, t ≤ n; s ≠ t).
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, bi ≤ n; ai ≠ bi; 0 ≤ pi ≤ 99).
No more than one route is known between each pair of islands.
Output
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 |
3 0.19 |
#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(最短路)的更多相关文章
- URAL 1934 Black Spot --- 最短的简单修改
右侧是1.维护的同时保持最短路p值至少,我有直接存款(1-p).该概率不满足,为了使这个值极大. #include <iostream> #include <cstdlib> ...
- URAL 1934 spfa算法
D - Black Spot Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- URAL 1934 最短路变形
DES:给出起点和终点.给出所有小岛的编号.所有路径的起始点.和遇到怪物的概率.要求在最短路的条件下维护遇见怪物的概率最小的路径.就是用 SPFA算法.每条路的权值设为1.最短路即为途径的岛数最少.同 ...
- URAL 1085 Meeting(最短路)
Meeting Time limit: 2.0 secondMemory limit: 64 MB K friends has decided to meet in order to celebrat ...
- ural 1355. Bald Spot Revisited(数的素因子划分)
1355. Bald Spot Revisited Time limit: 1.0 secondMemory limit: 64 MB A student dreamt that he walked ...
- URAL 2069 Hard Rock (最短路)
题意:给定 n + m 个街道,问你从左上角走到右下角的所有路的权值最小的中的最大的. 析:我们只要考虑几种情况就好了,先走行再走列和先走列再走行差不多.要么是先横着,再竖着,要么是先横再竖再横,要么 ...
- 1934. Black Spot(spfa)
1934 水题 RE了N久 后来发现是无向图 #include <iostream> #include<cstring> #include<algorithm> # ...
- URAL 1355. Bald Spot Revisited(数论)
题目链接 题意 : 一个学生梦到自己在一条有很多酒吧的街上散步.他可以在每个酒吧喝一杯酒.所有的酒吧有一个正整数编号,这个人可以从n号酒吧走到编号能整除n的酒吧.现在他要从a号酒吧走到b号,请问最多能 ...
- Ural 1741 Communication Fiend(隐式图+虚拟节点最短路)
1741. Communication Fiend Time limit: 1.0 second Memory limit: 64 MB Kolya has returned from a summe ...
随机推荐
- 图书馆管理系统SRS
1.任务概述 1.1目标 主要提供图书信息和读者基本信息的维护以及借阅等功能.本系统是提高图书管理工作的效率,减少相关人员的工作量,使学校的图书管理工作真正做到科学.合理的规划,系统.高效的实施. 1 ...
- 如何在redhat下安装办公软件(openoffice)
在redhat的client版本中自带有办公软件libreoffice,而在server版的redhat中却没有自带的办公软件,那么,如何在redhat的server版下安装办公软件呢? 方法一:配置 ...
- android baseApplication 基类
package com.free.csdn.base; import java.io.File;import java.util.ArrayList;import java.util.List; im ...
- Visual Studio安装卸载模板
Visual Studio中有两种类型的模板:项目模板和项模板 一.已安装模板: 默认情况下,与产品一起安装的模板位于以下位置: ①\<Visual Studio 安装目录>\Common ...
- hdu 1025 dp 最长上升子序列
//Accepted 4372 KB 140 ms //dp 最长上升子序列 nlogn #include <cstdio> #include <cstring> #inclu ...
- Ubuntu 14.10 下Ganglia监控Hadoop集群
前提是已经安装好Ganglia和Hadoop集群 1 Master节点配置hadoop-metrics2.properties # syntax: [prefix].[source|sink|jmx] ...
- Pattern和Matcher
java util本身提供了Pattern和Matcher(java.util.regex.Pattern,Matcher),两个类均是与正则表达式相关的类,其中: java.util.regex是一 ...
- OpenSesame:一个能够攻击fixed-pin设备的工具
OpenSesame是一种设备,这种设备可以通过无线技术来打开任何一个设有固定密码的车库门,我从中发现了一个攻击无线固定pin码设备的新方法. 演示视频以及详细信息: opensesame源代码:ht ...
- 一个简单的Dump转文本工具—Dump2Text
每次电脑重装都得烦心,要把庞大的IDE重新配置一次,正准备安装Visual Stdio 2010,上网找镜像的时候发现,Visual Stdio 2013推出了Community版,不仅没有lite掉 ...
- How to Write Doc Comments for the Javadoc Tool
http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html This document describe ...