1.  

1003. Emergency (25)

  1.  
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
  1.  

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. /* dijstra的变种
  2. 1. 求最短路的总可能路径~(每次更新节点到集合S(已找到最短路的点集)距离时 若dist[i] = dist[v0] +map[v0][i] 将
  3. Count[i]+= Count[v0]; 若相等 则总路径数此次不变)
  4. 2. 在距离最短情况下,求最多能带多少护士去~~ (每次更新节点到集合S(已找到最短路的点集)距离时 若dist[i] = dist[v0] +map[v0][i] 将
  5. 更新护士值 为护士最多的那个值)
  6. */
  7. #include "iostream"
  8. using namespace std;
  9. #define INF 99999999
  10. int n, m;
  11. int cost[];
  12. int Mcost[];
  13. int dist[];
  14. int map[][];
  15. int Count[] ;
  16. void dijkstra(int v0,int n) {
  17. bool visited[] = { false };
  18. dist[v0] = ;
  19. Mcost[v0] = cost[v0];
  20. visited[v0] = true;
  21. for (int i = ; i < n; i++) {
  22. int MIN = INF;
  23. for (int j = ; j < n; j++) {
  24. if (!visited[j]) {
  25. if (dist[j] < MIN) {
  26. v0 = j;
  27. MIN = dist[j];
  28. }
  29. }
  30. }
  31. visited[v0] = true;
  32. for (int i = ; i < n; i++) {
  33. if (!visited[i]) {
  34. if (dist[i] > MIN + map[v0][i] ) {
  35. dist[i] = MIN + map[v0][i];
  36. Mcost[i] = Mcost[v0] + cost[i];
  37. Count[i] = Count[v0];
  38. }
  39. else if (dist[i] == MIN + map[v0][i] ) {
  40. Count[i] += Count[v0];
  41. if (Mcost[i] < Mcost[v0] + cost[i]) {
  42. Mcost[i] = Mcost[v0] + cost[i];
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }
  49. int main() {
  50. int v, e, c1, c2;
  51. cin >> v >> e >> c1 >> c2;
  52. for (int i = ; i < v; i++) {
  53. cin >> cost[i];
  54. Count[i] = ;
  55. }
  56. for (int i = ; i < v; i++)
  57. for (int j = ; j < v; j++) {
  58. map[i][j] = INF;
  59. }
  60. for (int i = ; i < e; i++) {
  61. int a, b, c;
  62. cin >> a >> b >> c;
  63. map[a][b] = map[b][a] = c;
  64. if (a == c1)
  65. Mcost[b] = cost[c1] + cost[b];
  66. else if (b == c1)
  67. Mcost[a] = cost[c1] + cost[a];
  68. }
  69. for (int i = ; i < v; i++) {
  70. dist[i] = map[c1][i];
  71. }
  72. dijkstra(c1,v);
  73. cout << Count[c2] <<" "<< Mcost[c2] << endl;
  74. return ;

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

  1. PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组

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

    problem 1003 Emergency (25)(25 point(s)) As an emergency rescue team leader of a city, you are given ...

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

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

  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 1003 Emergency

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

随机推荐

  1. hadoop2.4.0 安装配置 (2)

    hdfs-site.xml 配置如下: <?xml version="1.0" encoding="UTF-8"?> <?xml-styles ...

  2. [转载]C#中获取时间戳(UnixTime)的方法

    .Net中没有封装获取时间戳(UnixTime,相对于1970年1月1日凌晨的毫秒数)的方法.因此本人写了如下方法实现. 提醒在摸索中的朋友,注意方法中的四舍五入.关于讨论四舍五入的方法,可以在这里找 ...

  3. java常见内存溢出(OOM)

    jvm内存区域 程序计数器一块很小的内存空间,作用是当前线程所执行的字节码的行号指示器. java栈与程序计数器一样,java栈(虚拟机栈)也是线程私有的,其生命周期与线程相同.通常存放基本数据类型, ...

  4. ubuntu下firefox安装Adobe Flash Player

    转自ubuntu系统自带的火狐(firefox)如何安装Adobe Flash 当你刚装完系统,发现打开某些网站时,提示你"需要安装flash",然后你点击确定,过了一会,提示你安 ...

  5. var a=[]; 和 var a=new Array(); 的区别,为什么前者效率高

    因为 JSON格式的语法是引擎直接解释的.而new Array 则需要调用Array的构造器.还有就是1.当你需要将一个数字转化为字符串时可以这样定义:var s=""+1; 这样 ...

  6. SDUT 1570 C 旅行(DFS)

    点我看题目 题意 : 中文不详述. 思路 :就是DFS一下,只要到达终点条数就加1,然后再注意一下方向,因为我就是没注意方向WA了,只能向上向右走,x是行,所以向上是x-1,向右是y+1,因为我没弄好 ...

  7. php PDO连接mysql以及字符乱码处理

    <?php //mysql 的 PDO $dsn = "mysql:dbname=cqkx;host:localhost"; $username = "root&q ...

  8. 135. Candy

    题目: There are N children standing in a line. Each child is assigned a rating value. You are giving c ...

  9. android 颜色收集及部分gridview样式设置

    < ?xml version="1.0" encoding="utf-8" ?> < resources> < color nam ...

  10. Java之关键字static和final的使用

    static 在Java中声明属性.方法时,可使用关键字static来修饰. 1.static变量       按照是否静态的对类成员变量进行分类可分两种:一种是被static修饰的变量,叫静态变量或 ...