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 ...
随机推荐
- 如何在ubuntu下使用samba创建共享
快速简单的创建共享,比网上那些乱七八糟过时的文档强太多 原文地址: https://help.ubuntu.com/community/How%20to%20Create%20a%20Network% ...
- 日期 Date()
1.Date 对象用于处理日期和时间.创建 Date 对象的语法:var myDate=new Date()Date 对象会自动把当前日期和时间保存为其初始值.2.参数形式有以下5种: new Dat ...
- Linux简单部署svn服务
最近需要练习一下svn的命令行使用方法,以便编写自动化部署的脚本,但是不敢用正式的svn库进行练习,所以自己部署了一个svn服务,用来练习 1.安装svn server 我用的是ubuntu $apt ...
- 泛型2(lambda表达式/参数绑定)
lambda 表达式: Lambda表达式完整的声明格式如下: [capture list] (params list) mutable exception-> return type { fu ...
- [原创]用WinRAR实现VC源代码快速压缩创建
[原创]用WinRAR实现VC源代码快速压缩创建 by edata @ cnblogs.com/edata 2017-5-8 22:31:57 我们有的时候需要对vc项目压缩打包,因为vc项目的无关文 ...
- Spark Programming Guide《翻译》
转载必须注明出处:梁杰帆 在这里要先感谢原作者们!如果各位在这里发现了错误之处,请大家提出 1.Initializing Spark Spark程序必须做的第一件事就是创建一个SparkCon ...
- ssh 操作
1.登录 ssh 用户名@远程地址 2.拷贝:scp -r 本地文件夹 远程文件夹(user@ip:目录) 3.从ssh中临时退出: a. ~ (control+z) b.查看后台任务:jobs c ...
- VUE学习(一)
1.搭建vue环境 2.了解 v-on 事件监听,常常跟事件(click,mousemove,change等鼠标或者手势事件)在一起,eg:v-on:click,语法糖——:(冒号) 需要在meth ...
- Flask Web开发实战(入门、进阶与原理解析)
URL重定向 错误响应 > 如果你想手动返回错误响应,可以使用Flask提供的abort()函数. XML 上下文全局变量 [](https://img2018.cnblogs.com/blog ...
- 记一个SpringBoot中属性注入失败的问题Consider defining a bean of type ''' in your configuration
今天遇到的一个问题: 代码检查了好几次,都没有错误,但是启动时就会报错Consider defining a bean of type ''' in your configuration. 启动类在c ...