1003. Emergency (25)
来源:互联网 发布:移动4g突然连不上网络 编辑:程序博客网 时间:2024/06/05 17:18
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<stdio.h>#define inf 99999999int n,m,c1,c2;int mark[510];int dis[510];int road[510];int adj[510][510];int sumteam[510];int singleteam[510];void init(){int i,j;for(i=0;i<n;i++){dis[i]=inf;road[i]=1;for(j=0;j<n;j++){adj[i][j]=inf;}adj[i][i]=0;}}void dijkstra(int s){mark[s]=1;dis[s]=0;sumteam[s]=singleteam[s];int i,newp=s;while(1){for(i=0;i<n;i++){if(mark[i]==0&&adj[newp][i]<inf){if(dis[i]>dis[newp]+adj[newp][i]){dis[i]=dis[newp]+adj[newp][i];sumteam[i]=sumteam[newp]+singleteam[i];road[i]=road[newp];//}else if(dis[i]==dis[newp]+adj[newp][i]){road[i]=road[newp]+road[i];if(sumteam[i]<sumteam[newp]+singleteam[i]){sumteam[i]=sumteam[newp]+singleteam[i];}}}}int min=inf;for(i=0;i<n;i++){if(mark[i]==0&&dis[i]<inf){if(dis[i]<min){min=dis[i];newp=i;}}}mark[newp]=1;if(min==inf||newp==c2){break;}}}int main(){int i,e1,e2,length;scanf("%d %d %d %d",&n,&m,&c1,&c2);for(i=0;i<n;i++){scanf("%d",&singleteam[i]);}init();for(i=0;i<m;i++){scanf("%d %d %d",&e1,&e2,&length);adj[e1][e2]=length;adj[e2][e1]=length;}dijkstra(c1);printf("%d %d",road[c2],sumteam[c2]);}
- 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)
- zabbix邮件报警(系统邮箱)
- hive函数大全
- Android studio断点调试(全在这里)
- 下述程序有什么问题?
- 登陆一下好吗??--实验吧
- 1003. Emergency (25)
- Python3.5——文件读与写详解(下)
- 序 自学开始
- Linux 基础知识与常用命令
- 模板
- OpenJudge百炼-2802-小游戏-C语言-深度优先搜索
- Floyd's Cycle Detection Algorithm
- Angularjs Controller 间通信方式、vue组件之间通信
- php环境搭建