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

这道题没能完全通过,有一个测试点始终没办法通过...问了大神大神还没回复我,后续可能会更新

照样记录出错的过程:
1.图是无向图,忘记使g.edge[i][j]=g.edge[j][i]=weight;
2.需要减枝,确定了目标的最短路径后就需要停止循环了
3.最短路径的条数的计算有问题,没有考虑到如果1-2有3条,那么1-2-4的时候4要考虑上2的3条
if(相等)
countpath[i]=countpath[i]+countpath[k];
if(小于)
countpath[i]=countpath[k]
 #include<iostream>
using namespace std;
#define MAX 10000000
#define MAX_VERTEX_NUM 505
int count1[MAX_VERTEX_NUM];
int dist[MAX_VERTEX_NUM];
int path[MAX_VERTEX_NUM];
typedef struct
{
int vexs[MAX_VERTEX_NUM];
int edges[MAX_VERTEX_NUM][MAX_VERTEX_NUM];
int vexnum,edgenum;
}MGraph; void CreateDN_AM(MGraph &G,int n,int e)
{
G.vexnum=n;
G.edgenum=e; int i,j,k;
int weight;
for(i=;i<n;i++)
cin>>G.vexs[i];
for(i=;i<n;i++)
for(j=;j<n;j++)
G.edges[i][j]=MAX;
for(k=;k<e;k++)
{
cin>>i>>j>>weight;
G.edges[i][j]=G.edges[j][i]=weight;
}
} void ShortestPath_DJ(MGraph &G,int v,int t)
{
int i,j,k,min; int final[MAX_VERTEX_NUM]; for(i=;i<G.vexnum;i++)
{
dist[i]=G.edges[v][i];
if(dist[i]<MAX)
path[i]=G.vexs[v]+G.vexs[i];
else
path[i]=;
final[i]=;
count1[i]=;
}
dist[v]=;
final[v]=;
for(j=;j<G.vexnum;j++)
{
min=MAX;
for(i=;i<G.vexnum;i++)
if(dist[i]<min && final[i]==)
{
min=dist[i];
k=i;
}
if(k==t) break;
final[k]=;
for(i=;i<G.vexnum;i++)
{
if(dist[i]>dist[k]+G.edges[k][i] && final[i]==)
{
dist[i]=dist[k]+G.edges[k][i];
path[i]=path[k]+G.vexs[i];
count1[i]=count1[k];
}
else if(dist[i]==dist[k]+G.edges[k][i]&&final[i]==){
count1[i]=count1[i]+count1[k];
if(path[i]<path[k]+G.vexs[i]){
path[i]=path[k]+G.vexs[i];
}
}
}
}
} int main()
{
MGraph G;
int n,m,s,t;
cin>>n>>m>>s>>t;
CreateDN_AM(G,n,m);
ShortestPath_DJ(G,s,t);
cout<<count1[t]<<" "<<path[t];
}

更新更新:

出错的那一个测试点是因为没有考虑到当起点和目标是同一个城市的情况(真是奇怪..)

这样的话直接输出1和这个城市的救援队数量。

加了一句这个就过了

        if(s==t){
cout<<''<<" "<<G.vexs[s];
}

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

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

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

  2. PAT 1003. Emergency (25)

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

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

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

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

  5. PAT 甲级 1003. Emergency (25)

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

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

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

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

  8. [图算法] 1003. Emergency (25)

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

  9. PAT (Advanced level) 1003. Emergency (25) Dijkstra

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

随机推荐

  1. .NET XML序列化与反序列化

    闲着没事,写了两个通用的XML序列化与反序列化的方法. 贴出来当作笔记吧! /// <summary> /// XML序列化 /// </summary> /// <ty ...

  2. 用android去写一个小程序

    前言: 软工的一个小作业:实现"黄金分割小游戏", 需要结对编程,队友:陈乐云    共用时两天. 早期思路设计: 采用键值对的形式,以Map作为存储结构.优点:能够将数据与用户对 ...

  3. Webform server.transfer 用法

    server.transfer 特点: 1:大家熟悉的一个特点,用server.transfer 跳转到新页面时,浏览器的地址是没有改变的(因为重定向完全在服务器端进行,浏览器根本不知道服务器已经执行 ...

  4. 理工科应该的知道的C/C++数学计算库(转)

    理工科应该的知道的C/C++数学计算库(转) 作为理工科学生,想必有限元分析.数值计算.三维建模.信号处理.性能分析.仿真分析...这些或多或少与我们常用的软件息息相关,假如有一天你只需要这些大型软件 ...

  5. DOM的概念(1)

    什么是DOM? 通过 JavaScript,您可以重构整个HTML文档.您可以添加.移除.改变或重排页面上的项目.要改变页面的某个东西,JavaScript就需要对HTML文档中所有元素进行访问的入口 ...

  6. Android--RecyclerView的封装使用

    1,用了很长一段时间的RecyclerView,在项目中用的频率也越来越频繁(因为踩得坑也越来越多了),或过头来看,感觉一直在写RecyclerView.Adapter中的三个方法和一个内部类,感觉很 ...

  7. PHP 返回JSON

    有个朋友说PHP不能返回JSON对象,作为.net的我认为应该是可以的,设置一下header 就行了. 果不然,google 一下,备忘如下: <?php $result = array('Na ...

  8. [Asp.net]Uploadify上传大文件,Http error 404 解决方案

    引言 之前使用Uploadify做了一个上传图片并预览的功能,今天在项目中,要使用该插件上传大文件.之前弄过上传图片的demo,就使用该demo进行测试.可以查看我的这篇文章:[Asp.net]Upl ...

  9. php 读取输出其他文件的方法

    ob_start();iconv('utf-8','gb2312',readfile('1.html')); //直接输出文本内容echo '<hr>'; $data = file_get ...

  10. 【转载】调试利器 autoexp.dat

    转载:http://www.cppblog.com/flyinghare/archive/2010/09/27/127836.html autoexp.dat入门(调试时自定义变量显示) VC在调试状 ...