PAT甲级1003. Emergency (25)
来源:互联网 发布:软件著作权资助 编辑:程序博客网 时间:2024/05/20 11:26
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
#include <cstdio>using namespace std;#include <vector>const int MAX=500+10;vector<int> cityMap[MAX]; //邻接表 int Dis[MAX][MAX]={0}; //Length of the pair of cities int RT[MAX];//rescue teamsint visited[MAX]={0};int minLen=1<<30;int current_Len=0;int total_Min=0;int maxRescue=-1;int current_Rescue=0;void DFS(int s,int d){ if(current_Len>minLen) return; /* 优先级minLen>maxRescure */ if(s==d){ if(current_Len<minLen) { minLen=current_Len; total_Min=1; maxRescue=current_Rescue; } else if(current_Len==minLen) { total_Min++; if(current_Rescue>maxRescue) maxRescue=current_Rescue; } return; } for(int i=0;i<cityMap[s].size();i++){ int tmpIndex=cityMap[s][i]; if(visited[tmpIndex]==0){ current_Len+=Dis[s][tmpIndex]; current_Rescue+=RT[tmpIndex]; visited[tmpIndex]=1; DFS(tmpIndex,d); current_Len-=Dis[s][tmpIndex]; current_Rescue-=RT[tmpIndex]; visited[tmpIndex]=0; } }}int main(){ int N,M,start,destination; scanf("%d %d %d %d",&N,&M,&start,&destination); for(int i=0;i<N;i++){ scanf("%d",&RT[i]); } for(int i=0;i<M;i++){ int c1,c2,len; scanf("%d %d %d",&c1,&c2,&len); cityMap[c1].push_back(c2); cityMap[c2].push_back(c1); Dis[c1][c2]=len; Dis[c2][c1]=len; } visited[start]=1; current_Rescue=RT[start]; DFS(start,destination); printf("%d %d",total_Min,maxRescue); return 0;}
- Pat甲级1003. Emergency (25)
- 【PAT甲级】1003. Emergency (25)
- PAT甲级1003. Emergency (25)
- 1003. Emergency (25) PAT 甲级
- PAT甲级 1003. Emergency (25)
- PAT甲级1003. Emergency (25)
- PAT 甲级 1003. Emergency (25)
- PAT 甲级 1003.Emergency
- [PAT-甲级]1003.Emergency
- PAT 甲级 1003. Emergency
- 【PAT甲级】【C++】1003. Emergency (25)
- PAT TEST甲级1003. Emergency (25)
- PAT甲级练习1003. Emergency (25)
- PAT 甲级1003. Emergency (25) DIJKSTRA
- 1003. Emergency (25)-PAT甲级真题(Dijkstra算法)
- PAT甲级 1003.Emergency(25) 题目翻译与答案
- pat 甲级 1003 Emergency
- pat甲级_路径问题(例题:pat 1003 Emergency (25))
- Struts2之对Web资源的获取及登陆统计示例
- 外挂学习之路(9)--- 普通攻击call
- bitmap图片压缩
- 计蒜客等和的分隔子集
- Java概述
- PAT甲级1003. Emergency (25)
- IOS开发学习笔记(二)
- 【Android 进阶】 Android 回调理解
- 斜率优化总结
- Codeforces ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS
- 使用实体分区创建SWAP
- 实验1:Visual C++6.0 开发环境入门
- 109. Convert Sorted List to Binary Search Tree
- 深入学习的艺术——每一个程序员都必不可少的技能