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做法:

 #include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <iostream>
using namespace std;
#define size 505
int city[size],map[size][size],team[size],roadnum[size],dis[size];
int n,m,s,e;
void dijstra(int s,int e){
int i,j,k;
dis[s]=;//表示已经在集合中
roadnum[s]=;
while(s!=e){
for(i=;i<n;i++){
if((dis[i]==-&&map[s][i]!=-)||(dis[i]>&&dis[s]>&&map[s][i]>&&dis[i]>dis[s]+map[s][i])){//更新
dis[i]=dis[s]+map[s][i];
team[i]=team[s]+city[i];
roadnum[i]=roadnum[s];
}
else{
if(dis[i]>&&dis[s]>&&map[s][i]>&&dis[i]==dis[s]+map[s][i]){
if(team[i]<team[s]+city[i])
team[i]=team[s]+city[i];
roadnum[i]+=roadnum[s];
}
}
}
dis[s]=;
int min=-;
for(i=;i<n;i++){
if(dis[i]>&&(min==-||dis[i]<min)){
min=dis[i];
s=i;
}
}
}
}
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
scanf("%d %d %d %d",&n,&m,&s,&e);
int i,j,k;
for(i=;i<n;i++){
scanf("%d",&city[i]);
}
int a,b,l;
for(i=;i<n;i++){
dis[i]=-;
team[i]=city[i];
for(j=;j<n;j++){
map[i][j]=map[j][i]=-;//初始化
}
}
for(i=;i<m;i++){
scanf("%d %d %d",&a,&b,&l);
if(map[a][b]==-||map[a][b]>l)//确保最小化
map[a][b]=map[b][a]=l;
}
dijstra(s,e);
printf("%d %d\n",roadnum[e],team[e]);
return ;
}

DFS做法:

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

  1. PAT-1003 Emergency (25 分) 最短路最大点权+求相同cost最短路的数量

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

  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. PAT1003:Emergency

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

  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. PAT 甲级 1003. Emergency (25)

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

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

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

  9. PAT-1003 Emergency(Dijkstra)

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

随机推荐

  1. 合并datagridview 条件合并行数据

    public void HeBing() { int rowsCount; int CellCount; rowsCount = FG1.Rows.Count; CellCount = FG1.Col ...

  2. Delphi XE8中开发DataSnap程序常见问题和解决方法 (二)想对DBExpress的TSQLDataSet写对数据库操作的SQL语句出错了!

    当我们搞定DataSnap后,我们进入客户端程序开发阶段了,我们建立了客户端模块后,打算按照刚才开发服务器的步骤开发客户端程序,随后加入了DBExpress的TSQLDataSet,设定数据库连接后, ...

  3. iOS 开发技术体系

    iOS 开发技术体系图: - 层级 | 主要框架 - ---------------------|--------------------------------------------------- ...

  4. OC 术语表

    术语表 本附录包含了很多会用到的非正式定义术语.有些术语与Obective-C语言有关,其他术语则有自己的语源,来自面向对象程序设计的规范.在后一种情况中,术语的含义只有明确应用于Obective-C ...

  5. C语言编程基础

    主流C语言编译器介绍 关于GNU规范的语法扩展 用C语言构建一个可执行程序的流程 宏定义(无参宏定义和带参宏定义),C语言宏定义详解 条件编译,C语言条件编译详解 原码.反码.补码及位操作符,C语言位 ...

  6. Maven配置与安装

    最近重装了一下系统,便重新安装与配置了maven,记录这个过程并分享出来. 注意:maven安装需要Java依赖,我这里使用的是jdk1.8. 1.安装并配置环境变量 首先在 maven 官网下载 m ...

  7. 洛谷P4526 【模板】自适应辛普森法2(Simpson法)

    题面 传送门 题解 据说这函数在\(x>15\)的时候趋近于\(0\) 据说当且仅当\(a<0\)时积分发散 所以直接套自适应\(simpson\)吧-- //minamoto #incl ...

  8. Linux--CentOS7使用firewalld打开关闭防火墙与端口

    1.firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status f ...

  9. 190221协程与IO模型

    一.协程 又称微线程 协程是一种用户态的轻量级的线程 在单线程下实现的并发,例如:yield 优点: 无需线程上下文切换的开销 无需原子操作锁定及同步的开销 方便切换控制流,简化编程模型 高并发,高扩 ...

  10. phpstorm利用database连接mysql数据库

    首先声明一点,database只能连接一个已存在的数据库,不能创建数据库 连接一个已存在的数据库步骤: 1,找到database:连续点击俩次shift,输入database就能找到了 2,点击绿色的 ...