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 Specification:

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, C​1​​ and C​2​​ - 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 c​1​​, c​2​​ 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 C​1​​ to C​2​​.

Output Specification:

For each test case, print in one line two numbers: the number of different shortest paths between C​1​​ and C​2​​, 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 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1

Sample Output:

2 4
 #include<iostream>
#include<cstring> using namespace std; static const int INFTY = (<<);
static const int MAX = ;
static const int WHITE = ;
static const int GRAY = ;
static const int BLACK = ; int n, M[MAX][MAX], Team[MAX];
int w[MAX], num[MAX]; void dijsktra(int source){
int d[MAX];
int color[MAX];
for(int i=;i<n;i++){
d[i] = INFTY;
color[MAX] = WHITE;
}
memset(w, , sizeof(w));
memset(num, , sizeof(num));
d[source] = ;
color[source] = GRAY;
num[source] = ;
w[source] = Team[source];
while(true){
int minv = INFTY;
int u = -;
for(int i=;i<n;i++){
if(minv>d[i]&&color[i]!=BLACK){
u = i;
minv = d[i];
}
}
if(u==-){
break;
}
color[u] = BLACK;
for(int v=;v<n;v++){
if(color[v]!=BLACK&&M[u][v]!=INFTY){
if(d[v]>d[u]+M[u][v]){
d[v] = d[u] + M[u][v];
color[v] = GRAY;
w[v] = w[u] + Team[v];
num[v] = num[u];
}
else if(d[v]==d[u]+M[u][v]){
if(w[v]<w[u] + Team[v]){
w[v] = w[u] + Team[v];
}
num[v] += num[u];
}
}
}
}
} int main(){
int road, source, target;
cin>>n>>road>>source>>target;
for(int i=;i<n;i++){
for(int j=;j<n;j++){
M[i][j] = INFTY;
}
}
int cnt;
for(int i=;i<n;i++){
cin>>cnt;
Team[i] = cnt;
}
int u, v, cost;
for(int i=;i<road;i++){
cin>>u>>v>>cost;
M[v][u] = M[u][v] = cost;
}
dijsktra(source);
cout<<num[target]<<" "<<w[target]<<endl;
return ;
}

需要注意的是MAX的设定,很奇怪的是,题目给定最大是500,设定五百会有一些测试点过不去,得开的稍微大一点。还有就是,数组需要进行初始化。

1003 Emergency(25 分)的更多相关文章

  1. 1003 Emergency (25分) 求最短路径的数量

    1003 Emergency (25分)   As an emergency rescue team leader of a city, you are given a special map of ...

  2. PAT 1003 Emergency (25分)

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  3. 1003 Emergency (25分)

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  4. 【PAT甲级】1003 Emergency (25 分)(SPFA,DFS)

    题意:n个点,m条双向边,每条边给出通过用时,每个点给出点上的人数,给出起点终点,求不同的最短路的数量以及最短路上最多能通过多少人.(N<=500) AAAAAccepted code: #in ...

  5. PAT 解题报告 1003. Emergency (25)

    1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...

  6. PAT 1003. Emergency (25)

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  7. PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  8. 1003 Emergency (25)(25 point(s))

    problem 1003 Emergency (25)(25 point(s)) As an emergency rescue team leader of a city, you are given ...

  9. PAT 甲级 1003. Emergency (25)

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  10. PAT 甲级1003 Emergency (25)(25 分)(Dikjstra,也可以自己到自己!)

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

随机推荐

  1. shiro+springmvc 都使用缓存

    基于涛哥shiro案例16 的这时候要配置service方法的缓存 在spring-config.xml添加 <context:annotation-config /> <cache ...

  2. 剑指offer:二位数组中的查找

    准备找实习期间,复习一下数据相关内容,刷刷题. 题目描述: 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样 ...

  3. 《TCP/IP 详解 卷1:协议》第 10 章:用户数据报协议

    引言 UDP 稍微扩展了IP协议,使得包可以在进程间传送,而不仅仅是在主机件.--<CSAPP> IP 数据报是指 IP 层端到端的传输单元.分组(packet)是 IP 层和链路层的传输 ...

  4. STL的集合set

    集合: 集合是由元素组成的一个类,其成员可以是一个集合,也可以是一个原子,通常一个元素在一个集合中不能多次出现:由于对实现集合不是很理解,只简单写下已有的STL中的set集合使用: C++中set基本 ...

  5. .NET WinForm下StatusStrip控件如何设置分隔线及部分子控件右对齐

    ssInfo.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;//StatusStrip 控件 tsslUpdate.Alignment = ...

  6. 0422数学口袋精灵bug发现

    团队成员的博客园地址: 蔡彩虹:http://home.cnblogs.com/u/caicaihong/ 曾治业:http://www.cnblogs.com/zzy999/ 蓝叶:http://w ...

  7. HDU 2103 Family planning

    http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,there are so m ...

  8. JavaScript下的new操作符做了什么?

    可以参考知乎的一篇文章:https://zhuanlan.zhihu.com/p/23987456 参考网上其他人的文章,new发生了以下操作 参考MDN:https://developer.mozi ...

  9. Delphi函数的out、var等关键字的作用,和使用场景

    问题描述 Delphi函数的out.var等关键字的作用,和使用场景 Delphi函数的out.var等关键字的作用,和使用场景,我知道var是作为传值调用,但是像out这个关键字又是什么作用呢? 解 ...

  10. 计算机网络【7】—— TCP的精髓

    参考文献: http://blog.chinaunix.net/uid-26275986-id-4109679.html TCP协议作为一个可靠的面向流的传输协议,其可靠性和流量控制由滑动窗口协议保证 ...