1003. Emergency (25)
来源:互联网 发布:中国工具书网络出版 编辑:程序博客网 时间:2024/06/07 01:19
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.
5 6 0 21 2 1 5 30 1 10 2 20 3 11 2 12 4 13 4 1Sample Output
2 4
这道题深搜代码我已经挂过了,深搜特别好写,但这个迪杰斯特拉我确实断断续续写了好几天,其中有一点一直困惑着我,今天势必要把这个点讲透讲明白,
#include<bits/stdc++.h>#define INF 99999999using namespace std;int N,M,C1,C2;int chess[501][501];int value[501];int dis[501];int vis[501];int amount[501];int team[501];void shortestPATH(int s){ int i,j; memset(vis,0,sizeof(vis)); memset(amount,0,sizeof(amount)); memset(team,0,sizeof(team)); team[s]=value[s]; amount[s]=1; int MIN,u,v; dis[s]=0; for(i=0;i<N;i++) { MIN=INF; u=-1; for(j=0;j<N;j++) { if(vis[j]==0 && dis[j]<MIN) { MIN=dis[j]; u=j; } } vis[u]=1; for(j=0;j<N;j++) { if(vis[j]==0 && dis[u]+chess[u][j]<dis[j]) { dis[j]=dis[u]+chess[u][j]; amount[j]=amount[u]; //amount[j]代表到达j点最短路的条数 team[j]=value[j]+team[u]; //team[j]代表救援队的数目 } else if(vis[j]==0 && dis[u]+chess[u][j]==dis[j]) { amount[j]+=amount[u]; int temp=team[u]+value[j]; if(temp>team[j]) team[j]=temp; } } }}int main(){ cin>>N>>M>>C1>>C2; int i,j; for(i=0;i<N;i++) { dis[i]=INF; cin>>value[i]; } for(i=0;i<N;i++) for(j=0;j<N;j++) chess[i][j]=INF; int sx,sy,st; for(i=0;i<M;i++) { cin>>sx>>sy>>st; chess[sx][sy]=chess[sy][sx]=st; } shortestPATH(C1); cout<<amount[C2]<<' '<<team[C2]<<endl; return 0;}
- 1003. Emergency (25)
- 1003. Emergency (25)-PAT
- (PAT)1003. Emergency (25)
- 1003. Emergency (25)
- 【C++】1003. Emergency (25)*
- 1003. Emergency (25)
- PAT 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- PAT 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- [PAT]1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- Could not calculate build plan Plugin org.apache.maven.pluginsmaven-resour
- 【转】Linux中常用操作命令
- Leetcode5 Rotate Image
- 养成良好编程习惯-写伪代码
- CV::MAT总结
- 1003. Emergency (25)
- sublime插件安装
- Mybatis动态更新
- 自定义控件(面试热门问题之一)
- 关于文本文件中的 "\n"
- C++中strcmp的头文件问题
- 清除svn密码
- 进程间同步
- opencv中函数