1003 Emergency (25分)

 

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 Specification:

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, C​1​​ and C​2​​ - 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 c​1​​, c​2​​ 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 C​1​​ to C​2​​.

Output Specification:

For each test case, print in one line two numbers: the number of different shortest paths between C​1​​ and C​2​​, 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

题意:n个城市m条路,每个城市有救援小组,联通城市之间的距离已知。
给定起点和终点,求从起点到终点的最短路径条数以及最短路径上的救援小组数目之和最大的那个 题解:和求Disjktra多重权值一样,
在更新中间节点路径更短的时候,顺带更新救援小组的数量
当最短路径相同的时候,更新最短路径条数
#include<iostream>
#include<cstdio>
#include<cstring>
#define MAX 1000000
using namespace std;
int a[][];
int num[];//每个村庄有多少个救援队
int dis[];//起点S到村庄j的最短距离
int val[];//起点S到村庄j可以聚集救援队的数量
int vis[];
int cnt[];//起点S到村庄j的最短路径有多少条
void dijkstra(int start, int n)
{
int i, j, k, min;
for (i = ; i < n; i++)//(初始化)存放起点到其余顶点的距离
dis[i] = a[start][i]; dis[start] = ;
val[start] = num[start];
cnt[start] = ; for (i = ; i < n; i++)
{
min = MAX;
k = -;
for (j = ; j < n; j++) //求出初始起点s直接到j点距离最短的点的下标值
{
if (vis[j]== && min > dis[j])
{
min = dis[j];
k = j;
}
}
vis[k] = ;
if (k == -)
return;
for (j = ; j <= n; j++)
{
if (dis[j] > dis[k] + a[k][j])//若找到其他途径比从1号顶点直接到目的顶点的距离短,则替换掉
{
cnt[j]=cnt[k];
dis[j] = dis[k] + a[k][j];
val[j]=num[j]+val[k];
} else if (dis[j] == dis[k] + a[k][j])//如果距离相同
{
cnt[j]=cnt[j]+cnt[k];
val[j] = max(val[j],val[k] + num[j]);//更新救援队数量
}
}
}
} int main()
{
int n, m;
int i;
int s, e;
cin>>n>>m>>s>>e;
for(int i=;i<n;i++)
cin>>num[i];
int t1,t2,t3;
memset(vis, , sizeof(vis));
memset(cnt, , sizeof(cnt));
memset(cnt, , sizeof(val));
memset(a, MAX, sizeof(a));//初始化所有点的距离/花费为无穷大
for (i = ; i < m; i++)
{
scanf("%d%d%d", &t1, &t2, &t3);
if (a[t1][t2] > t3)//去重
a[t1][t2] = a[t2][t1] = t3;
}
dijkstra(s, n);
printf("%d %d\n", cnt[e], val[e]);
return ;
}
 

1003 Emergency (25分) 求最短路径的数量的更多相关文章

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

  2. 【PAT甲级】1003 Emergency (25 分)(SPFA,DFS)

    题意:n个点,m条双向边,每条边给出通过用时,每个点给出点上的人数,给出起点终点,求不同的最短路的数量以及最短路上最多能通过多少人.(N<=500) AAAAAccepted code: #in ...

  3. 1003 Emergency (25分)

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

  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 (25)

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

  6. PAT 1003. Emergency (25)

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

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

  8. PAT 甲级 1003. Emergency (25)

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

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

随机推荐

  1. socket udp编程的一些积累的记录

    接了个小活,要求写udp的客户端,循环接收服务端的固定的指令并显示数据 我设计的逻辑是,用户在界面输入框输入服务器ip.端口,随后udp连接,开启线程循环接收,接收指令,解析成数据,存在结构体的lis ...

  2. 零基础入门python爬虫(一)

    ✍写在前面: 欢迎加入纯干货技术交流群Disaster Army:317784952 接到5月25日之前要交稿的任务我就一门心思想写一篇爬虫入门的文章,可是我并不会.还好有将近一个月的时间去学习,于是 ...

  3. restful api的那些事

    1.restful api 简介 传统api: 2.http状态码 3.数据结构格式 4.不可预知的api错误解决方案: 如使用框架,可写个类,重构错误提示.如TP框架可继承Handle并重载rend ...

  4. laravel框架学习笔记

    一.laravel的安装 1.composer 作用:主要管理php中的依赖关系(类似于yum源) 可以安装的软件: curl    //主要用到微信开发中 upload //文本操作 excel / ...

  5. Flask笔记1

    Flask笔记 首先明确一下,要运行一个动态网页,我们需要 一个 Web 服务器来监听并响应请求,如果请求的是静态文件它就直接将其返回,如果是动态 url 它就将请求转交给 Web 应用. 一个 We ...

  6. C/C++ 传递信息给Java

    #开始 今天有人问我C++怎么给Java传递消息 大概需求是 用C++写了一个窗口 需要把编辑框里面的东西传递给Java做处理 #解决过程 我现在能想到的有三个简单的方法 1. Socket编程 通过 ...

  7. 【转】直播流程,视频推流,视频拉流,简介,SMTP、RTMP、HLS、 PLPlayerKit

    原:https://www.cnblogs.com/baitongtong/p/11248966.html 1 .音视频处理的一般流程: 数据采集→数据编码→数据传输(流媒体服务器) →解码数据→播放 ...

  8. rapidxml编写xml文件(er)

    一.以rapidxml::node_declaration形式写xml文件第一行 int write(void) { ; rapidxml::xml_document<> doc; rap ...

  9. 从头学pytorch(四) softmax回归实现

    FashionMNIST数据集共70000个样本,60000个train,10000个test.共计10种类别. 通过如下方式下载. mnist_train = torchvision.dataset ...

  10. 2020年python学习进阶方向

     相信很多友人在学习python过程都会遇到很多 虽然python入门很容易  但是难免会遇到瓶颈 遇到问题没人交流 很难提升   对此 给你们简单指点学习方向  1.认识python linux基本 ...