PAT A1003. Emergency (25)
来源:互联网 发布:尚硅谷mysql视频下载 编辑:程序博客网 时间:2024/06/06 16:31
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.
5 6 0 21 2 1 5 30 1 10 2 20 3 11 2 12 4 13 4 1Sample Output
2 4
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int INF = 0x3fffffff;const int Max = 1111;int n,m,c1,c2;int Droop[Max]={0};int Road[Max][Max];int Num[Max];int d[Max];int droop[Max];bool Visit[Max];void Dijkstra (int s){memset(Num,0,sizeof(Num));fill(d,d+Max,INF);memset(droop,0,sizeof(droop));d[s]=0;droop[s]=Droop[s];Num[s]=1;for(int i=0;i<n;i++){int u=-1;int MIN = INF;for(int j=0;j<n;j++){if(Visit[j]==false&&d[j]<MIN){u=j;MIN=d[j];}}if(u==-1)return ;Visit[u]=true;for(int j=0;j<n;j++){if(Visit[j]==false&&Road[u][j]!=INF){if(d[u]+Road[u][j]<d[j]){d[j]=d[u]+Road[u][j];droop[j]=droop[u]+Droop[j];Num[j]=Num[u];}else if(d[u]+Road[u][j]==d[j]){ if(droop[u]+Droop[j]>droop[j])droop[j]=droop[u]+Droop[j]; Num[j]+=Num[u];}}}}}int main(){fill(Road[0],Road[0]+Max*Max,INF);memset(Visit,false,sizeof(Visit));int temp,ans,ins;scanf("%d%d%d%d",&n,&m,&c1,&c2);for(int i=0;i<n;i++){scanf("%d",&Droop[i]);}for(int i=0;i<m;i++){scanf("%d%d%d",&ans,&ins,&temp);Road[ans][ins]=temp;Road[ins][ans]=temp;}Dijkstra(c1);printf("%d %d\n",Num[c2],droop[c2]);system("pause");return 0;}
- PAT A1003 Emergency(25)
- PAT A1003. Emergency (25)
- pat-a1003. Emergency (25)
- PAT A1003 Emergency
- PAT甲级练习题A1003. Emergency
- a1003. Emergency (25)
- PAT A1003
- PAT-A1003
- 1003. Emergency (25)-PAT
- (PAT)1003. Emergency (25)
- Pat 1003 Emergency (25)
- PAT 1003. Emergency (25)
- PAT 1003. Emergency (25)
- [PAT]1003. Emergency (25)
- 【PAT】1003. Emergency (25)
- PAT 1003. Emergency (25)
- PAT 1003. Emergency (25)
- PAT 1003. Emergency (25)
- EasyPlayer安卓Android流媒体播放器实现直播过程中客户端快照功能
- AchartEngine 笔记
- iFunFactory是一家韩国游戏服务器公司
- jQuery知识点总结和归纳
- Java和JavaScript简单对比
- PAT A1003. Emergency (25)
- 安卓使用VideoView播放raw目录的视频和sd卡的视频
- WiKitude6.0中文教程
- 实现自定义checkbox、radio样式
- android studio 总结自己开发中常常用到的快捷键
- Java Jvm运行机制原理
- Leetcode_Plus One
- Node.js中的Buffer对象
- cf#402 E 大模拟