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. python 中对list去重

    本文去重的前提是要保证顺序不变,本文给出了多种实现方法,需要的朋友可以参考下 1.直观方法 最简单的思路就是: ids = [1,2,3,3,4,2,3,4,5,6,1] news_ids = [] ...

  2. .NET基础拾遗(1)类型语法基础和内存管理基础【转】

    http://www.cnblogs.com/edisonchou/p/4787775.html Index : (1)类型语法.内存管理和垃圾回收基础 (2)面向对象的实现和异常的处理 (3)字符串 ...

  3. pyqt5 通过QLinearGradient 绘制取色板

    要绘制HSV取色板,一般通过绘制前景色和背景色的方式实现,先绘制前景,然后绘制背景,前景是HSV颜色空间,从左到右,背景是亮度,从上到下,xs和ys是鼠标的当前的位置. def graphicsVie ...

  4. 占位符 css

    == 普通的英文半角空格   ==   ==   == no-break space (普通的英文半角空格但不换行)   == 中文全角空格 (一个中文宽度)   ==   == en空格 (半个中文 ...

  5. JAVA基础学习(4)之循环控制

    4循环控制 4.1 for循环 4.1.1 for循环 固定次数for循环 先执行一次do-while循环 其他while循环 Scanner in = new Scanner(System.in); ...

  6. vscode设置python代码补全时函数自动加上小括号

    vscode设置python代码补全时函数自动加上小括号 vscode的python代码补全插件默认安装时是不会自动补全括号的,感觉不是和方便 以下介绍下自动补上小括号的方法 可能部分同学设置了还是没 ...

  7. makefile的书写

    工作中会遇到makefile的书写,有必要做一些笔记.尽管网上有”万能模板“可以使用,但我觉得还是有必要从最基础的写起. 平常在windows下开发,不知道自己用过makefile,其实大部分IDE里 ...

  8. JS-apply、call、bind

    最近查看了很多关于apply的文章,就随手记录一下. Apply apply: 方法能劫持另外一个对象的方法,继承另外一个对象的属性. Function.apply(obj,args) 方法能接收两个 ...

  9. A Kill Cord for your Laptop

    前言 昨晚在朋友圈看到国外一篇文章利用U盘锁笔记本电脑,刚好有一个坏的金士顿U盘,所以就折腾了一下. 准备 USB设备*1 Arch系统*1 走过的坑 因为systemd-udevd带起来的进程是ro ...

  10. 开关电源ac-dc推荐电路

    在使用AC-DC电源模块SA系列时,如果碰到对模块的输出纹波噪声要求较高或对EMC要求严格的场合,应对模块进行必要的滤波处理使到满足不同环境的特殊要求,以下推荐一滤波电路供参考: 图中各元件的说明:1 ...