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. 【音乐欣赏】《Siren》 - The Chainsmokers / Aazar

    曲名:Siren 作者:The Chainsmokers . Aazar [00:00.00] 作曲 : Alex Pall/Andrew Taggart/Alexis Duvivier [00:01 ...

  2. 解决:执行python脚本,提示错误:/usr/bin/python^M: 解释器错误: 没有那个文件或目录。

    执行python脚本,提示错误: /usr/bin/python^M: 解释器错误: 没有那个文件或目录. 产生错误原因: \r字符被显示为^M,这时候只需要删除这个字符就可以了. Linux环境下: ...

  3. pyqt:布局删除小部件

    参照:https://stackoverflow.com/questions/5899826/pyqt-how-to-remove-a-widget import sip layout.removeW ...

  4. Azure IoT Hub 十分钟入门系列 (2)- 使用模拟设备发送设备到云(d2c)的消息

    本文主要分享一个案例: 10分钟- 使用Python 示例代码和SDK向IoT Hub 发送遥测消息 本文主要有如下内容: 了解C2D/D2C消息: 了解IoT Hub中Device的概念 了解并下载 ...

  5. linux 配置IPSAN存储

    一 SAN存储 1.1 SAN存储介绍 存储区域网络(Storage Area Network,简称SAN)采用网状通道(Fibre Channel ,简称FC,区别与Fiber Channel光纤通 ...

  6. selenium配合phantomjs实现爬虫功能,并把抓取的数据写入excel

    # -*- coding: UTF-8 -*- ''' Created on 2016年5月13日 @author: csxie ''' import datetime from Base impor ...

  7. ubuntu 先安装php再安装apache后,php不解析

    本来服务器是nginx ,把他改成了apache, 安装apache, sudo apt-get updatesudo apt-get install apache2 然后访问ip,不成功 vim / ...

  8. cmake使用的一些补充

    一般使用cmake生成vs项目的时候,要么生成32位的要么生成64位的. 怎样将32位和64位在一个工程中打开呢,联系我们自己建立的工程都是32位和64位在一起的,就动手开始了. 实验对象是openc ...

  9. 拿到别人的Django程序如何在本地RUN起来

    在Pycharm IDE下 Edit Configurations 1.检查Python interpreter 2.检查 Working directory 3.Settings 数据库配置

  10. js正则验证表达式验证

    /* 合法uri */ export function validateURL(textval) {  const urlregex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\ ...