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

  1. 5 6 0 2
  2. 1 2 1 5 3
  3. 0 1 1
  4. 0 2 2
  5. 0 3 1
  6. 1 2 1
  7. 2 4 1
  8. 3 4 1

Sample Output

  1. 2 4

仔细读题,最后需要输出的是最短路径中能够派出急救队数目和最大的数值

源代码:

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <string>
  5. #include <cstring>
  6. #include <vector>
  7. #include <algorithm>
  8. using namespace std;
  9.  
  10. const int maxn = ;
  11. const int INF = 0x3f3f3f3f;
  12. int n,m,st,ed,G[maxn][maxn],weight[maxn];
  13. int d[maxn],w[maxn],num[maxn];
  14. bool vis[maxn]={false};
  15.  
  16. void dij(int s) {
  17. fill(d,d+maxn,INF);
  18. memset(num,,sizeof(num));
  19. memset(w,,sizeof(w));
  20. d[s]=;
  21. w[s]=weight[s];
  22. num[s]=;
  23. for(int i=;i<n;++i) {
  24. int u=-,MIN=INF;
  25. for(int j=;j<n;++j) {
  26. if(vis[j]==false&&d[j]<MIN) {
  27. u=j;
  28. MIN=d[j];
  29. }
  30. }
  31. if(u==-) return;
  32. vis[u]=true;
  33. for(int v=;v<n;++v) {
  34. if(vis[v]==false&&G[u][v]!=INF) {
  35. if(d[u]+G[u][v]<d[v]) {
  36. d[v]=d[u]+G[u][v];
  37. w[v]=w[u]+weight[v];
  38. num[v]=num[u];
  39. } else if(d[u]+G[u][v]==d[v]) {
  40. if(w[u]+weight[v]>w[v]) {
  41. w[v]=w[u]+weight[v];
  42. }
  43. num[v]+=num[u];
  44. }
  45. }
  46. }
  47. }
  48. }
  49. int main() {
  50. scanf("%d%d%d%d",&n,&m,&st,&ed);
  51. for(int i=;i<n;++i) {
  52. scanf("%d",&weight[i]);
  53. }
  54. int u,v;
  55. fill(G[],G[]+maxn*maxn,INF);
  56. for(int i=;i<m;++i) {
  57. scanf("%d%d",&u,&v);
  58. scanf("%d",&G[u][v]);
  59. G[v][u]=G[u][v];
  60. }
  61. dij(st);
  62. printf("%d %d\n",num[ed],w[ed]);
  63. return ;
  64. }

PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组的更多相关文章

  1. PAT 1003. Emergency (25)

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

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

  3. PAT 解题报告 1003. Emergency (25)

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

  4. PAT 甲级 1003. Emergency (25)

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

  5. PAT 1003 Emergency[图论]

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

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

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

  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)(25 分)(Dikjstra,也可以自己到自己!)

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

  9. PAT Advanced 1003 Emergency (25) [Dijkstra算法]

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

随机推荐

  1. 温故而知新 Volley源码解读与思考

    相比新的网络请求框架Volley真的很落后,一无是处吗,要知道Volley是由google官方推出的,虽然推出的时间很久了,但是其中依然有值得学习的地方.  从命名我们就能看出一些端倪,volley中 ...

  2. PhiloGL学习(3)——程序员的法宝—键盘、鼠标

    前言 上一篇文章中介绍了如何让对象动起来,本文介绍如何让场景响应我们的鼠标和键盘以控制场景的缩放及对象的转动和移动等. 一. 原理分析 有了上一篇文章的基础,我们已经知道了如何让场景和对象动起来.本文 ...

  3. component及刚体rigidbody用法

    关于getcomponent函数,rigidbody(2d)的嵌套关系及用法 1.getcomponent函数 在unity中脚本可以看成是可定义的组件,我们经常要访问同一对象或不同对象中的脚本,可以 ...

  4. JDBC的基本用法

    一.编程步骤 1.加载驱动 Class forName("com.mysql.jdbc.Driver"):mysql驱动 Class forName("oralce.jd ...

  5. ES6新特性之Symbol使用细节

    在迭代器章节的时候出现过[Symbol.iterator ]的属性,那么到底Symbo到底是什么? 答:Symbol是ES6新定义的一种值,它既不是字符串,也不是对象,而是为javaScript增加的 ...

  6. java语言插入数组中一个数,仍然能够实现排序

    package com.llh.demo; import java.util.Scanner; /** * * @author llh * */ public class Demo16 { /* * ...

  7. GCC(警告.优化以及调试选项)

    GCC(警告.优化以及调试选项) [介绍] gcc and g++分别是gnu的c & c++编译器   gcc/g++在执行编译工作的时候,总共需要4步   1.预处理,生成.i的文件 预处 ...

  8. SQL——按照季度,固定时间段,分组统计数据

    最近在工作中接到了一个需求,要求统计当月以10天为一个周期,每个周期的数据汇总信息.假设有一张表如下: 表table_test中 ID           AMOUNT         CREATE_ ...

  9. echarts2.2.7本地搭建

    1.首先下载echarts2.2.7,解压到本地,解压后的目录如下: 2.在WebContent下建立一个名为build的目录,复制echarts2.2.7下面的build下面的dist目录到ecli ...

  10. 深入理解JavaScript中的继承:原型链篇

    一.何为原型链 原型是一个对象,当我调用一个对象的方法时,如果该方法没有在对象里面,就会从对象的原型去寻找.JavaScript就是通过层层的原型,形成原型链. 二.谁拥有原型 任何对象都可以有原型, ...