1003. Emergency (25)


时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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.

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
/* dijstra的变种
1. 求最短路的总可能路径~(每次更新节点到集合S(已找到最短路的点集)距离时 若dist[i] = dist[v0] +map[v0][i] 将
Count[i]+= Count[v0]; 若相等 则总路径数此次不变)
2. 在距离最短情况下,求最多能带多少护士去~~ (每次更新节点到集合S(已找到最短路的点集)距离时 若dist[i] = dist[v0] +map[v0][i] 将
更新护士值 为护士最多的那个值)
*/
#include "iostream"
using namespace std;
#define INF 99999999
int n, m;
int cost[];
int Mcost[];
int dist[];
int map[][];
int Count[] ;
void dijkstra(int v0,int n) {
bool visited[] = { false };
dist[v0] = ;
Mcost[v0] = cost[v0];
visited[v0] = true;
for (int i = ; i < n; i++) {
int MIN = INF;
for (int j = ; j < n; j++) {
if (!visited[j]) {
if (dist[j] < MIN) {
v0 = j;
MIN = dist[j];
}
}
}
visited[v0] = true;
for (int i = ; i < n; i++) {
if (!visited[i]) {
if (dist[i] > MIN + map[v0][i] ) {
dist[i] = MIN + map[v0][i];
Mcost[i] = Mcost[v0] + cost[i];
Count[i] = Count[v0];
}
else if (dist[i] == MIN + map[v0][i] ) {
Count[i] += Count[v0];
if (Mcost[i] < Mcost[v0] + cost[i]) {
Mcost[i] = Mcost[v0] + cost[i];
}
}
}
}
}
}
int main() {
int v, e, c1, c2;
cin >> v >> e >> c1 >> c2;
for (int i = ; i < v; i++) {
cin >> cost[i];
Count[i] = ;
}
for (int i = ; i < v; i++)
for (int j = ; j < v; j++) {
map[i][j] = INF;
}
for (int i = ; i < e; i++) {
int a, b, c;
cin >> a >> b >> c;
map[a][b] = map[b][a] = c;
if (a == c1)
Mcost[b] = cost[c1] + cost[b];
else if (b == c1)
Mcost[a] = cost[c1] + cost[a];
}
for (int i = ; i < v; i++) {
dist[i] = map[c1][i];
}
dijkstra(c1,v);
cout << Count[c2] <<" "<< Mcost[c2] << endl;
return ;

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

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

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

  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. PAT 解题报告 1003. Emergency (25)

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

  4. PAT 甲级 1003. Emergency (25)

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

  5. PAT 1003 Emergency[图论]

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

  6. 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 ...

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

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

  8. 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 ...

  9. PAT 1003 Emergency

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

随机推荐

  1. python xlrd,xlwt 读写excel文件

    python 读excel文件,需要xlrd库.下载地址:https://pypi.python.org/pypi/xlrd python 写excel文件,需要xlwt库.下载地址:https:// ...

  2. mongodb MongoDB 聚合 group

    MongoDB 聚合 MongoDB中聚合(aggregate)主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果.有点类似sql语句中的 count(*). 基本语法为:db.col ...

  3. python 操作sqlite数据库

    '''SQLite数据库是一款非常小巧的嵌入式开源数据库软件,也就是说 没有独立的维护进程,所有的维护都来自于程序本身. 在python中,使用sqlite3创建数据库的连接,当我们指定的数据库文件不 ...

  4. Python中zip()函数用法

    定义:zip([iterable, …])zip()是Python的一个内建函数,它接受一系列可迭代的对象作为参数,将对象中对应的元素打包成一个个tuple(元组),然后返回由这些tuples组成的l ...

  5. ubuntu下的翻译软件goldendict

    转自ubuntu下的翻译软件 看着一些API虽然能看懂一个大概,但总想知道每个单词的意思.问题是英语水平有限,所以只能来找一些翻译软件,像windows下来用的有道估计是不行了(也没去试到定行不行), ...

  6. 用PersonalRank实现基于图的推荐算法

    今天我们讲一个下怎么使用随机游走算法PersonalRank实现基于图的推荐. 在推荐系统中,用户行为数据可以表示成图的形式,具体来说是二部图.用户的行为数据集由一个个(u,i)二元组组成,表示为用户 ...

  7. 【HDOJ】2828 Lamp

    DLX简单题目. /* */ #include <iostream> #include <sstream> #include <string> #include & ...

  8. Wordpress Jigoshop插件路径泄露漏洞

    漏洞名称: Wordpress Jigoshop插件路径泄露漏洞 CNNVD编号: CNNVD-201311-109 发布时间: 2013-11-12 更新时间: 2013-11-12 危害等级:   ...

  9. 软件介绍(apache lighttpd nginx)

    一.软件介绍(apache  lighttpd  nginx) 1. lighttpd Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点.lighttpd是众多 ...

  10. 如何使用eclipse进行嵌入式Linux的开发

    如何使用eclipse进行嵌入式Linux的开发 作者:曾宏安,华清远见嵌入式学院高级讲师. 如何使用eclipse进行嵌入式Linux的开发 习惯了在windows环境下开发的程序员在转到Linux ...