pat1003. Emergency (25)
1003. Emergency (25)
As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.
Input
Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C1 to C2.
Output
For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather.
All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.
Sample Input
5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1
Sample Output
2 4
dijstra做法:
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <iostream>
using namespace std;
#define size 505
int city[size],map[size][size],team[size],roadnum[size],dis[size];
int n,m,s,e;
void dijstra(int s,int e){
int i,j,k;
dis[s]=;//表示已经在集合中
roadnum[s]=;
while(s!=e){
for(i=;i<n;i++){
if((dis[i]==-&&map[s][i]!=-)||(dis[i]>&&dis[s]>&&map[s][i]>&&dis[i]>dis[s]+map[s][i])){//更新
dis[i]=dis[s]+map[s][i];
team[i]=team[s]+city[i];
roadnum[i]=roadnum[s];
}
else{
if(dis[i]>&&dis[s]>&&map[s][i]>&&dis[i]==dis[s]+map[s][i]){
if(team[i]<team[s]+city[i])
team[i]=team[s]+city[i];
roadnum[i]+=roadnum[s];
}
}
}
dis[s]=;
int min=-;
for(i=;i<n;i++){
if(dis[i]>&&(min==-||dis[i]<min)){
min=dis[i];
s=i;
}
}
}
}
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
scanf("%d %d %d %d",&n,&m,&s,&e);
int i,j,k;
for(i=;i<n;i++){
scanf("%d",&city[i]);
}
int a,b,l;
for(i=;i<n;i++){
dis[i]=-;
team[i]=city[i];
for(j=;j<n;j++){
map[i][j]=map[j][i]=-;//初始化
}
}
for(i=;i<m;i++){
scanf("%d %d %d",&a,&b,&l);
if(map[a][b]==-||map[a][b]>l)//确保最小化
map[a][b]=map[b][a]=l;
}
dijstra(s,e);
printf("%d %d\n",roadnum[e],team[e]);
return ;
}
DFS做法:
pat1003. Emergency (25)的更多相关文章
- PAT-1003 Emergency (25 分) 最短路最大点权+求相同cost最短路的数量
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- PAT 解题报告 1003. Emergency (25)
1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...
- PAT 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT1003:Emergency
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 1003 Emergency (25)(25 point(s))
problem 1003 Emergency (25)(25 point(s)) As an emergency rescue team leader of a city, you are given ...
- PAT 甲级 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 1003 Emergency (25分) 求最短路径的数量
1003 Emergency (25分) As an emergency rescue team leader of a city, you are given a special map of ...
- PAT-1003 Emergency(Dijkstra)
1003 Emergency (25 分) As an emergency rescue team leader of a city, you are given a special map of y ...
随机推荐
- Log--检查各数据库日志的使用情况
-- Recovery model, log reuse wait description, log file size,-- log usage size and compatibility lev ...
- java學習書
轉載 成为Java顶尖程序员 ,看这11本书就够了 以下是我推荐给Java开发者们的一些值得一看的好书.但是这些书里面并没有Java基础.Java教程之类的书,不是我不推荐,而是离我自己学习 Java ...
- 谷歌Google浏览器去广告插件ABP插件安装与使用
---恢复内容开始--- 最新版本的 Chrome 浏览器,主版本号为 67,数字签名日期为 2018.05.30.对 Chrome 的扩展(俗称插件)安装策略进行了调整——只允许在 Chrome 应 ...
- mac下redis和zookeeper启动及测试命令
mac下启动命令: sudo su - root cd /usr/local/bin/ ./redis-server ../etc/redis.conf cd /software/zook ...
- dubbo源码分析--dubbo spi解析
1. 什么叫SPI? 简单总结就是一种使用类名字符串来动态实例化java类的方式,也就是反射. 2. java SPI与Dubbo SPI有什么区别 (此图来自网上,我没有刻意去截图) 然后在这个文件 ...
- Ajaxa的原生使用方法
Ajax整合了JavaScript.xml.CSS等现有技术而成,全称为Asynchronous JavaScript And XML,即异步的 JavaScript和xml.它使用了JavaScri ...
- 月薪3万+的大数据人都在疯学Flink,为什么?
身处大数据圈近5年了,在我的概念里一直认为大数据最牛的两个东西是Hadoop和Spark.18年下半年的时候,我突然发现身边很多大数据牛人都是研究学习Flink,甚至连Spark都大有被冷落抛弃的感觉 ...
- [集合]线程安全的HashMap
一.一般模式下线程安全的HashMap 默认情况常用的HashMap都是线程不安全的,在多线程的环境下使用,常常会造成不可预知的,莫名其妙的错误.那么,我们如何实现一个线程安全的HashMap呢?其中 ...
- 《Andrew Ng深度学习》笔记1
深度学习概论 1.什么是神经网络? 2.用神经网络来监督学习 3.为什么神经网络会火起来? 1.什么是神经网络? 深度学习指的是训练神经网络.通俗的话,就是通过对数据的分析与计算发现自变量与因变量的映 ...
- Hdp 4 window MR 注意事项
1,本机未安装HDP, 在代码中加一个环境变量,跳过检查. Environment.SetEnvironmentVariable("HADOOP_HOME", @"D ...