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. sjtu1285 时晴时雨

    Description Taring 喜欢晴天,也喜欢雨天. Taring说:我想体验连续的\(K\)天的晴朗,去远足,去放歌:我还想再这\(K\)个晴天之后,再去体验连续的K天的云雨,去感受落雨时的 ...

  2. http://blog.csdn.net/bluejoe2000/article/details/39521405#t9

    http://blog.csdn.net/bluejoe2000/article/details/39521405#t9

  3. 李洪强漫谈iOS开发[C语言-021]-运算符

  4. Protel封装库

    一.目录下面的一些封装库中,根据元件的不同封装我们将其封装分为二大类:一类是分立元件的封装,一类是集成电路元件的封装 1.分立元件类: 电容:电容分普通电容和贴片电容: 普通电容在Miscellane ...

  5. BIOS与CMOS有什么区别

    本文介绍BIOS与CMOS区别,BIOS是什么?BIOS全称Basic Input/Output System,所以BIOS本身个是系统简称,所以我们常说的BIOS芯片确切的讲是写有BIOS系统的芯片 ...

  6. CentOS5.5 下编译安装 LAMP

    大纲 1.安装gcc编译器 2.卸载rpm安装的http和mysql软件 3.编译安装php依赖包 4.安装apache软件 5.安装mysql软件 6.安装php软件 7.安装memcache ph ...

  7. poj3140Contestants Division

    链接 这叫树形DP吗..?断开某条边 求剩下两颗树数权值和的差最小 dfs一遍 枚举边 查了n久 wa n次  dp数组没初始化.. 在poj上1A感觉应该挺爽 #include <iostre ...

  8. scaleform 注意事项

    在使用 自带的UI .fla 里面的组建时 需要把自己建立的fla进行如下设置.  文件-发布设置-flash-脚本actionscript3.0设置——舞台:自动声明舞台实例    

  9. @Resource和@Autowired

    @Resource的作用相当于@Autowired,只不过@Autowired按byType自动注入,而@Resource默认按 byName自动注入罢了.@Resource有两个属性是比较重要的,分 ...

  10. Oracle MySQL Server 安全漏洞

    漏洞名称: Oracle MySQL Server 安全漏洞 CNNVD编号: CNNVD-201401-317 发布时间: 2014-01-22 更新时间: 2014-01-22 危害等级: 中危  ...