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. Array.prototype.slice.call(arguments)

    Array.prototype.slice.call(arguments)能够将具有length属性的对象转化为数组, 可以理解为将arguments转化成一个数组对象,让它具有slice方法 如: ...

  2. Struts2批量验证(POC)

    only poc , 再据结果利用EXP进一步测试: 支持 -u 单个url; -f 文本批量URL导入 url列表格式是https://www.baidu.com #! /usr/bin/env p ...

  3. C++之路进阶——codevs2306(晨跑)

    2306 晨跑 2009年省队选拔赛山东  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 大师 Master       题目描述 Description Elaxia最近迷恋 ...

  4. HDU-1274 展开字符串

    Problem Description 在纺织CAD系统开发过程中,经常会遇到纱线排列的问题.该问题的描述是这样的:常用纱线的品种一般不会超过25种,所以分别可以用小写字母表示不同的纱线,例如:abc ...

  5. android 案例二 登录界面

    效果图: 运行图:   总结: 编写这个简单的用户登录界面,主要用到了以下的知识:   java基础中的IO流的操作 用以读取.显示用户的信息 Android布局 线性布局和相对布局 数据的存储选在包 ...

  6. Python中递归的最大次数

    实际应用中遇到了一个python递归调用的问题,报错如下: RuntimeError: maximum recursion depth exceeded while calling a Python ...

  7. 一个简单的c# 贪吃蛇程序

    一个简单的c#贪吃蛇程序 程序分为界面设计和程序设计:界面设计和程序设计均参考了一些游戏实例,但是所有代码内容是本人编写. 由于看到别人写的程序并没有署名,这里的署名全部都是csdn官网. 游戏界面设 ...

  8. XP 安装Oralce 10g 数据库

    今天使用XP新建一个新数据库,下面是自己的操作方法, 电脑版本型号:Microsoft Windows XP Professional 版本 2002 Service Pack 3 Oracle版本型 ...

  9. 从oracle数据库中导出excel问题导致乱码的问题

    使用plsqldev工具将oracle的查询结果导出为excel,结果可以成功导出,但是使用libreoffice进行查看时,有好多记录都是空的. 使用python进行导出(openpyxl模块进行e ...

  10. YbSoftwareFactory 代码生成插件【十八】:树形结构下的查询排序的数据库设计

    树形结构的排序在中国特色下十分普遍也非常重要,例如常说的五大班子,党委>人大>政府>政协>纪委,每个班子下还有部门,岗位,人员,最终排列的顺序通常需要按权力大小.重要性等进行排 ...