PAT (Advanced Level) Practise 1003. Emergency (25)
2014-10-22 14:25
435 查看
1003. Emergency (25)
时间限制400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
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 <iostream> using namespace std; int n,m,c1,c2,small,big,cou; int price[510],mark[510]={0}; int a[510][510]={0}; void work(int mid,int s,int b) { int i; if(mid==c2) { if((s<small)||(small==0)) { small=s; cou=1; big=b; } else if(s==small) { cou++; if(b>big) big=b; } } for(i=0;i<n;i++) { if((a[mid][i]!=0)&&(mark[i]==0)) { mark[i]=1; work(i,s+a[mid][i],b+price[i]); mark[i]=0; } } return; } int main() { int i,x,y,z; cin>>n>>m>>c1>>c2; for(i=0;i<n;i++) cin>>price[i]; for(i=0;i<m;i++) { cin>>x>>y>>z; a[x][y]=z; a[y][x]=z; } small=0; big=0; cou=0; mark[c1]=1; work(c1,0,price[c1]); printf("%d %d\n",cou,big); system("pause"); return 0; }
相关文章推荐
- 1003. Emergency (25)——PAT (Advanced Level) Practise
- 1003. Emergency (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1003. Emergency (25) Dijstra扩展应用
- PAT (Advanced Level) Practise - 1003. Emergency (25)
- 浙大PAT (Advanced Level) Practise 1003. Emergency (25)
- PAT (Advanced Level) Practise 1101 Quick Sort (25)
- PAT (Advanced Level) Practise 1090 Highest Price in Supply Chain (25)
- PAT (Advanced Level) Practise 1002 A+B for Polynomials (25)
- PAT (Advanced Level) Practise 1017. Queueing at Bank (25)
- PAT (Advanced Level) Practise 1085 Perfect Sequence (25)
- PAT (Advanced Level) Practise 1105 Spiral Matrix (25)
- 1002. A+B for Polynomials (25)——PAT (Advanced Level) Practise
- 1006. Sign In and Sign Out (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1133 Splitting A Linked List (25)
- 1060. Are They Equal (25)【字符串处理】——PAT (Advanced Level) Practise
- 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise
- 1074. Reversing Linked List (25)【链表翻转】——PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1048 Find Coins (25)
- PAT (Advanced Level) Practise 1003 Emergency (25)
- PAT (Advanced Level) Practise 1013 Battle Over Cities (25)