1003. Emergency (25)
来源:互联网 发布:js函数必须有返回值 编辑:程序博客网 时间:2024/05/18 00:35
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 <cstdio># include <vector># include <queue># include <algorithm># include <climits>using namespace std;const int size = 505;typedef pair<int,int> edge;/*<to,dist>*/ typedef pair<int,int> point; /*<dist,cityNo>*/struct vertex{ vector<edge> e;};int Fw[size];int FwSum[size];int RoadCnt[size];vertex city[size];int main(){int i,j,tmp; int n,m,s,e; scanf("%d%d%d%d",&n,&m,&s,&e); for (i=0;i<n;i++) scanf("%d",Fw+i); for (i=0;i<m;i++) { int a,b,c;scanf("%d%d%d",&a,&b,&c);city[a].e.push_back(edge(b,c)); city[b].e.push_back(edge(a,c)); } /**dijkstra**/ priority_queue<point,vector<point>,greater<point> > pri_que; int dist[size]; fill(dist,dist+n,INT_MAX>>1); fill(RoadCnt,RoadCnt+n,1); dist[s] = 0; FwSum[s] = Fw[s]; pri_que.push(point(dist[s],s)); while (!pri_que.empty()) { point loca = pri_que.top();pri_que.pop(); if (dist[loca.second] < loca.first) continue;vector<edge>& adj = city[loca.second].e;for (i=0;i<adj.size();i++) if (dist[adj[i].first] > dist[loca.second] + adj[i].second) { dist[adj[i].first] = dist[loca.second] + adj[i].second;pri_que.push(point(dist[adj[i].first],adj[i].first));RoadCnt[adj[i].first] = RoadCnt[loca.second]; FwSum[adj[i].first] = FwSum[loca.second] + Fw[adj[i].first]; } else if (dist[adj[i].first] == dist[loca.second] + adj[i].second) {RoadCnt[adj[i].first] += RoadCnt[loca.second]; FwSum[adj[i].first] = max(FwSum[adj[i].first],FwSum[loca.second] + Fw[adj[i].first]); } } /**dijkstra**/ printf("%d %d\n",RoadCnt[e],FwSum[e]); 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)
- Android InputMethodManager 控制软键盘
- IOS tableView通过代码自定义cell
- 【计算机基础】字符编码笔记:ASCII,Unicode和UTF-8
- 《大型网络技术架构》笔记 1
- 有时候,事情就是很简单,可是你就是找不到原因
- 1003. Emergency (25)
- Bootloader介绍
- 黑马程序员 多线程
- Eclipse中将一个android项目当做另外一个android项目的library
- [leetcode-206]Reverse Linked List(c)
- MFC给Static Text赋值
- 数学模板 - 组合数学
- javax.imageio.IIOException: Not a JPEG file: starts with 0x47 0x49
- 设计模式-迭代器模式