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

使用变形的dijkstra算法  并且随时更新最短路径的数目以及能够搜集到的队伍数目。

 #include <iostream>
#include <vector>
#include <cstdlib>
using namespace std; #define MaxDistance 10000
vector< vector <int>> GMatrix;
vector<int> dist;
vector<int> teams; int N,M,start,en; void dijkstra()
{
vector<int> flag(N, );
vector<int> pathcount(N, );
vector<int> amount(N, );
for (size_t i = ; i < N; i++)//initial the dist
{
if (GMatrix[start][i] != -)
dist.push_back(GMatrix[start][i]);
}
amount[start] = teams[start];
pathcount[start] = ; while()
{
int min = MaxDistance;
int k;
for (size_t j = ; j < N; j++)
{
if ((flag[j] == ) && (dist[j] < min))
{
min = dist[j];
k = j;
}
}
if (k == en|| min==MaxDistance) break; //can not find the mini or find the end node, then break the iterative while(1)
flag[k] = ;
for (size_t j = ; j < N; j++)
{
int temp = dist[k] + GMatrix[k][j];
if ((flag[j] == ) && (temp < dist[j]))
{
dist[j] = temp;
amount[j] = amount[k] + teams[j]; //update the teams you can gather
pathcount[j] = pathcount[k];// update the shortest road sums
}
else if ((flag[j] == ) && (temp == dist[j]))
{
pathcount[j] += pathcount[k]; //update
if (amount[k] + teams[j]>amount[j])
amount[j] = amount[k] + teams[j]; //update
}
}
}
//for (size_t i = 0; i < N; i++)//output the dist for check
//{
// cout << dist[i] << " ";
//}
//cout << endl;
cout << pathcount[en] << " " << amount[en] << endl; }
int main()
{
cin >> N >> M >> start >> en;
for (size_t i = ; i < N; i++)//input the teams
{
int t; cin >> t;
teams.push_back(t);
}
for (size_t i = ; i < N; i++)//initial the GMtraix
{
vector<int> arr(N, MaxDistance);
GMatrix.push_back(arr);
GMatrix[i][i] = ;//for the same start and end, the dist=0;
}
for (size_t i = ; i < M; i++)//input the road to the graph
{
int left, right, road;
cin >> left >> right >> road;
GMatrix[left][right] = road; GMatrix[right][left] = road;
}
dijkstra(); return ;
}

1003. Emergency的更多相关文章

  1. PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)

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

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

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

  3. PAT 1003. Emergency (25)

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

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

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

  5. PAT 1003 Emergency

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

  6. PAT 1003 Emergency[图论]

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

  7. 1003 Emergency (25 分)

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

  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

    PAT甲级1003. Emergency 题意: 作为一个城市的紧急救援队长,你将得到一个你所在国家的特别地图.该地图显示了几条分散的城市,连接着一些道路.每个城市的救援队数量和任何一对城市之间的每条 ...

  10. PAT 甲级 1003. Emergency (25)

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

随机推荐

  1. iOS tableView 静态单元格的实现

    本文转自:http://home.cnblogs.com/u/wendingding/ iOS开发UI篇—简单介绍静态单元格的使用 一.实现效果与说明 说明:观察上面的展示效果,可以发现整个界面是由一 ...

  2. 从零开始一个iOS项目(一)——基本准备以及cocopods的安装

    项目开发分为:独立开发和迭代开发,我主要讲独立开发,若读者是迭代开发,希望公司的代码一定要规范,便能省去许多麻烦,也能从中获益,闲时也可接些外包,赚一些外快,也是美差,然而独立开发最能锻炼人的能力. ...

  3. NPOI对Excel的操作(Sheet转DataTable、List<T>)

    通过NPOI对Excel进行操作,这里主要是读取的操作.封装到ExcelHelper操作类中. 1 using System.Collections.Generic; 2 using NPOI.HSS ...

  4. Oracle 时间差计算

    两个Date类型字段:START_DATE,END_DATE,计算这两个日期的时间差(分别以天,小时,分钟,秒,毫秒): 天: ROUND(TO_NUMBER(END_DATE - START_DAT ...

  5. 利用iframe实现无刷新上传处理

    继上一篇对上传异常进行处理之后,当上传异常的时候的错误体验并不是很好,这里介绍用iframe来进行错误提示 拦截错误 @ExceptionHandler(MaxUploadSizeExceededEx ...

  6. Spring MVC - 配置Spring MVC

    写在前面的话: 现在开始一段新的学习历程:Spring MVC.还是按照原来的三步走学习模式(what.why.how)进行讲解. 1.Spring MVC是什么(what) Spring MVC属于 ...

  7. df,du,mount

    df 查看当前系统中文件系统的使用情况 $df [-aTh]缺省选项查看当前系统的所有文件系统 -a列出所有的信息 -T列出文件系统类型 -hhuman-readable,用合适的单位表示大小 $df ...

  8. gdb 定位 oops call trace

    [    1.454380] BUG: unable to handle kernel NULL pointer dereference at 00000000000005d0[    1.47402 ...

  9. keepalived高可用反向代理的nginx

    实验系统: (1)CentOS 6.6_x86_64: (2)共有三台主机,本实验以ip地址来命名主机,即131主机.132主机.133主机. 实验前提:防火墙和selinux都关闭,主机之间时间同步 ...

  10. [转]Asp.net MVC 利用PartialView 构造自定义菜单

    本文转自:http://www.cnblogs.com/huyq2002/archive/2012/01/06/2314838.html 在VS2010中利用Asp.net MVC自带的模板生成的菜单 ...