1003. Emergency (25)
2016-12-16 13:47
381 查看
1003. Emergency (25)
时间限制400 ms
内存限制
65536 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 21 2 1 5 30 1 10 2 20 3 11 2 12 4 13 4 1
Sample Output
2 4
# include<iostream> # include<vector> using namespace std; const int INF=1000000; int price[501][501]; int people[501]; int dist[501]; int isread[501]; int path1[501]; int count1[501]; void dijstra(int b,int N){ int begin=b; int i,j; int fir=0; dist[b]=0; path1[b]=people[b]; while(1){ if(fir==0) fir=1; else{ int m=INF; for(i=N-1;i>=0;i--){ if(isread[i]==0&&dist[i]<m){ m=dist[i]; begin=i; } } } if(isread[begin]==1) break; //cout<<"&"<<begin<<"&"; isread[begin]=1; for(i=0;i<N;i++){ if(price[begin][i]!=INF&&isread[i]==0){ if(price[begin][i]+dist[begin]<dist[i]){ dist[i]=price[begin][i]+dist[begin]; count1[i]=count1[begin]; path1[i]=path1[begin]+people[i]; //cout<<i<<"="<<begin<<endl; } else if(price[begin][i]+dist[begin]==dist[i]){ count1[i]+=count1[begin]; if(path1[begin]+people[i]>path1[i]) path1[i]=path1[begin]+people[i]; //cout<<i<<"+="<<begin<<endl; } } } } } int main(){ int N,M,C1,C2; cin>>N>>M>>C1>>C2; int i,j; int temp1,temp2,temp3; for(i=0;i<N;i++){ cin>>people[i]; dist[i]=INF; } for(i=0;i<N;i++) for(j=0;j<N;j++) price[i][j]=INF; for(i=0;i<M;i++){ cin>>temp1>>temp2>>temp3; price[temp1][temp2]=temp3; price[temp2][temp1]=temp3; } for(i=0;i<N;i++){ isread[i]=0; path1[i]=0; count1[i]=1; } /* for(i=0;i<N;i++){ cout<<endl; for(j=0;j<N;j++) cout<<price[i][j]<<" "; }*/ dijstra(C1,N); cout<<count1[C2]<<" "<<path1[C2]<<endl; //cout<<count1[0]; }感想:只要人数不出现负数,dijstra贪心就可以解决一切问题
相关文章推荐
- 1003. Emergency (25)
- PAT 1003. Emergency (25)
- pat 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- pat-a1003. Emergency (25)
- 1003. Emergency (25)
- 【PAT Advanced Level】1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- Pat甲级1003. Emergency (25)
- PAT (Advanced Level) Practise 1003. Emergency (25)
- PAT_A 1003. Emergency (25)
- 1003. Emergency (25)(floyd)
- 1003. Emergency (25)
- 1003. Emergency (25)
- PAT甲级1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)