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 Specification:
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 Specification:
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
分析:水题。。Dijkstra模板套上就OK了,另外增加第二标尺、第三标尺时,初始化不能忘!
/** * Copyright(c) * All rights reserved. * Author : Mered1th * Date : 2019-02-22-17.23.41 * Description : A1003 */ #include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<algorithm> #include<string> #include<unordered_set> #include<map> #include<vector> #include<set> using namespace std; ; ; int n,m,st,ed; },w[maxn]={}; bool vis[maxn]={false}; void Dijkstra(int s){ fill(d,d+maxn,INF); d[s]=; w[s]=weight[s]; num[s]=; //这里初始化不能忘记! ;i<n;i++){ ,MIN=INF; ;j<n;j++){ if(vis[j]==false && d[j]<MIN){ u=j; MIN=d[j]; } } ) return; vis[u]=true; ;v<n;v++){ if(G[u][v]!=INF && vis[v]==false){ if(d[u]+G[u][v]<d[v]){ d[v]=d[u]+G[u][v]; num[v]=num[u]; w[v]=w[u]+weight[v]; } else if(d[u]+G[u][v]==d[v]){ if(w[v]<w[u]+weight[v]){ w[v]=w[u]+weight[v]; } num[v] += num[u]; //最短路径条数与点权无关,写在外面! } } } } } int main(){ #ifdef ONLINE_JUDGE #else freopen("1.txt", "r", stdin); #endif cin>>n>>m>>st>>ed; fill(G[],G[]+maxn*maxn,INF); ;i<n;i++){ scanf("%d",&weight[i]); } int a,b,t; ;i<m;i++){ scanf("%d%d%d",&a,&b,&t); G[a][b]=G[b][a]=t; } Dijkstra(st); printf("%d %d\n",num[ed],w[ed]); ; }
1003 Emergency (25 分)的更多相关文章
- 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 (25分)
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- 1003 Emergency (25分)
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 分)(SPFA,DFS)
题意:n个点,m条双向边,每条边给出通过用时,每个点给出点上的人数,给出起点终点,求不同的最短路的数量以及最短路上最多能通过多少人.(N<=500) AAAAAccepted code: #in ...
- 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 ...
- 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 ...
- PAT 甲级1003 Emergency (25)(25 分)(Dikjstra,也可以自己到自己!)
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
随机推荐
- L224
Astronomers have revealed details of mysterious signals emanating from a distant galaxy, picked up b ...
- Engineering Management
Engineering Management 工程師面對工作或挑戰時,可應用以下法則一步一步把工作規管和實施. 1. Planning 計劃 2. Organization 組織 ...
- HTTPS 通俗简介
为什么需要HTTPS 9个问题搞懂 https 来源 HTTP是明文传输的,也就意味着,介于发送端.接收端中间的任意节点都可以知道你们传输的内容是什么.这些节点可能是路由器.代理 等. 举个最常见的例 ...
- IDC:2014年的十大 IT 趋势
IDC:2014年的十大 IT 趋势 市场研究公司 IDC 近日发布报告,对 2014 年的十大科技行业发展趋势作出了预测.IDC 称,2014 年将是科技业"鏖战正酣"的一年,整 ...
- Python3下安装pip和MySQLdb
MySQLdb的安装更曲折了.还是按照正常方法安装,下载MySQL-python-1.2.5版本,解压后python setup.py install,发现怎么装都会报错“ConfigParser.N ...
- 实验吧—Web——WP之 头有点大
3. 首先看一下 .net framework 9.9 并没有9.9版本 可以考虑浏览器伪装用户代理 就得了解User-Agent ???何为user-agent User-Agent是Http协议中 ...
- Linux设备树
一.设备树编译 1.编译设备树:cd linux-x.xx & make dtbs,生成的dtb在目录linux-x.xx/arch/xxx/boot/dts下 2.反编译dtb,生成dts: ...
- FastAdmin 提示框 toastr 改变文字
如下图这个消息提示框为 toastr. FastAdmin 用的就是 toast 前端组件. 那如何改变这个文字呢? Karson:只要后台使用$this->success("自定义成 ...
- [脚本] 一个用于BMP到EPS转换的BAT脚本实现(需要安装bmeps)
最近用LaTeX写文章, 图片需要使用eps格式. 如果你安装了bmeps这个工具(一般你装了CTeX就自带这个工具的), 可以在需要转换的目录打开CMD窗口, 然后输入: bmeps -c a.jp ...
- linux挂载SD卡
(1)通过#fdisk -l命令确认板子上的linux系统是否识别SD卡 MP805M板子插入SD卡后显示 SD30 slot is without WPmmc1: new high speed SD ...