PAT A1003
来源:互联网 发布:淘宝店铺托管费用 编辑:程序博客网 时间:2024/06/08 10:19
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<algorithm>using namespace std;
const int maxn = 550;
const int INF = 1000000000;
int G[maxn][maxn];
int N,M,cityNow,citySave;
struct Node{
int key;
int d;
int numShort;
int maxWeight;
bool vis;
}n[maxn];
void Dkjstra(int start){
n[start].d = 0;
n[start].maxWeight = n[start].key;
n[start].numShort = 1;
for(int u=0;u<N;u++){
int min = INF;
int minI = -1;
for(int i=0;i<N;i++){
if(min>n[i].d&&n[i].vis==false){
min = n[i].d;
minI = i;
}
}
if(minI==-1){
return;
}
n[minI].vis = true;
for(int i=0;i<N;i++){
if(G[minI][i]!=INF&&n[i].vis==false){
if(n[i].d>n[minI].d+G[minI][i]){
n[i].numShort = n[minI].numShort;
n[i].d=n[minI].d+G[minI][i];
n[i].maxWeight=n[minI].maxWeight+n[i].key;
}else if(n[i].d==n[minI].d+G[minI][i]){
if(n[i].maxWeight<n[minI].maxWeight+n[i].key){
n[i].maxWeight =n[minI].maxWeight+n[i].key;
}
n[i].numShort+=n[minI].numShort;
}
}
}
}
}
int main(){
fill(G[0], G[0]+maxn*maxn, INF);
for(int i = 0;i<maxn;i++){
n[i].d = INF;
n[i].numShort = 0;
n[i].maxWeight = 0;
n[i].vis = false;
}
scanf("%d%d%d%d",&N,&M,&cityNow,&citySave);
for(int i=0;i<N;i++){
scanf("%d",&n[i].key);
}
for(int i=0;i<M;i++){
int a,b;
scanf("%d%d",&a,&b);
scanf("%d",&G[a][b]);
G[b][a]=G[a][b];
}
Dkjstra(cityNow);
printf("%d %d",n[citySave].numShort,n[citySave].maxWeight);
}
- PAT A1003
- PAT-A1003
- PAT A1003 Emergency
- PAT A1003 Emergency(25)
- PAT A1003. Emergency (25)
- pat-a1003. Emergency (25)
- PAT甲级练习题A1003. Emergency
- a1003. Emergency (25)
- 刷清橙OJ--A1003.画长方形1
- Tsinsen 清橙 A1003. 画长方形1 (循环)
- pat
- 【PAT】
- PAT
- PAT
- PAT
- PAT
- PAT
- PAT
- Spring定时任务的几种实现
- 为什么做java的web开发我们会使用struts2,springMVC和spring这样的框架?
- opencv中的SVM图像分类(一)
- Android Studio 解决Error occurred during initalization of VM
- 22. Generate Parentheses--递归法
- PAT A1003
- 层级遍历二叉树
- HTTP请求错误400、401、402、403、404、405、406、407、412、414、500、501、502解析
- 2017年伊始,你需要尝试的25个Android第三方库
- Spring与Quartz实现动态更新定时任务
- mariadb主从复制及互为主从配置过程
- PFN最新的目标检测算法
- InfoGAN介绍
- 设定网页最小最大宽度和高度(兼容IE6)