1003. Emergency (25)
来源:互联网 发布:我的世界mac版材质包 编辑:程序博客网 时间:2024/06/11 01:41
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<iostream>using namespace std;#define MAX 500#define INF 65535struct CityGraph{int rescue[MAX];//number of rescue teams in each cityint G[MAX][MAX];//city graphint Cities, Roads;//number of cities and roads}cities;void Dijkstra(int src,int dest){int isvisited[MAX]={0};//status of each city weather its path has been visitedint len[MAX];//shortest path length from src city to other citiesint count[MAX]={0};//count is the number of shortest path from src to destint team[MAX]={0};//team is the maximum amount of rescue teams we can possibly gather//=============Initiate================for(int i=0;i<cities.Cities;++i){len[i]=cities.G[src][i]; //initiate all lengthif(len[i]<MAX)//pay attention to it{team[i]=cities.rescue[src]+cities.rescue[i];count[i]=1;}}isvisited[src]=1; //src city is visited and path length is 0len[src]=0;team[src]=cities.rescue[src];//=============Dijkstra================int k=src;//k is the new added citywhile(k!=dest){int min=INF;int v;for(int j=0;j<cities.Cities;++j)if(!isvisited[j] && len[j]<min){v=j;min=len[j];}//add v to the visitedisvisited[v]=1;k=v;for(int j=0;j<cities.Cities;++j){if(!isvisited[j] && len[v]+cities.G[v][j]<len[j]){len[j]=len[v]+cities.G[v][j];team[j]=team[v]+cities.rescue[j];count[j]=count[v];}else if (!isvisited[j] && len[v]+cities.G[v][j]==len[j]){team[j]=team[v]+cities.rescue[j]>team[j] ? team[v]+cities.rescue[j] : team[j];count[j]=count[v]+count[j];}}}cout<<count[dest]<< ' '<<team[dest]<<endl;}int main(){int dest, start;cin>>cities.Cities>>cities.Roads>>start>>dest;for(int i=0;i<cities.Cities;++i){cin>>cities.rescue[i]; //number of rescue teams in each cityfor(int j=0;j<cities.Cities;++j)cities.G[i][j]= (i==j)?0:INF;}for(int i=0;i<cities.Roads;++i){int m,n,l;cin>>m>>n>>l;cities.G[m][n]=cities.G[n][m]=l;}Dijkstra(start,dest);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)
- Oracle数据库10个小问题
- 缓冲区溢出攻击原理分析
- Asynctask使用记录
- 生物节律
- 稀疏表示(SRC)
- 1003. Emergency (25)
- 《算法导论》学习笔记No.1--插入排序 增量法
- Android应用插件式开发解决方法
- Android学习笔记(三)之带有侧边索引的快速查找(跟带字母索引查找的通讯录差不多)
- poj--2706--Connect(极限大模拟)
- 解析SoapObject对象的一点心得发布:
- Oracle命名规范归纳
- 鸡兔同笼
- 1004. Counting Leaves (30)