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

分析:水题。。Dijkstra模板套上就OK了,另外增加第二标尺、第三标尺时,初始化不能忘!
 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-22-17.23.41
 * Description : A1003
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 using namespace std;
 ;
 ;
 int n,m,st,ed;
 },w[maxn]={};
 bool vis[maxn]={false};
 void Dijkstra(int s){
     fill(d,d+maxn,INF);
     d[s]=;
     w[s]=weight[s];
     num[s]=;     //这里初始化不能忘记!
     ;i<n;i++){
         ,MIN=INF;
         ;j<n;j++){
             if(vis[j]==false && d[j]<MIN){
                 u=j;
                 MIN=d[j];
             }
         }
         ) return;
         vis[u]=true;
         ;v<n;v++){
             if(G[u][v]!=INF && vis[v]==false){
                 if(d[u]+G[u][v]<d[v]){
                     d[v]=d[u]+G[u][v];
                     num[v]=num[u];
                     w[v]=w[u]+weight[v];
                 }
                 else if(d[u]+G[u][v]==d[v]){
                     if(w[v]<w[u]+weight[v]){
                         w[v]=w[u]+weight[v];
                     }
                     num[v] += num[u];  //最短路径条数与点权无关,写在外面!
                 }
             }
         }
     }
 }

 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     cin>>n>>m>>st>>ed;
     fill(G[],G[]+maxn*maxn,INF);
     ;i<n;i++){
         scanf("%d",&weight[i]);
     }
     int a,b,t;
     ;i<m;i++){
         scanf("%d%d%d",&a,&b,&t);
         G[a][b]=G[b][a]=t;
     }
     Dijkstra(st);
     printf("%d %d\n",num[ed],w[ed]);
     ;
 }

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

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

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

  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. 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 分)(SPFA,DFS)

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

  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. PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组

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

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

  9. PAT 甲级 1003. Emergency (25)

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

  10. 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. DevExpress v17.2新版亮点——VCL篇(一)

    用户界面套包DevExpress v17.2日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress VCL v17.2 的新功能,快来下载试用新版本! 全新的U ...

  2. 接收一条音频(系统音频)彩信,点菜单键选择View slideshow,不能播放,提示是否导入vCard

    [前提条件]: [操作步骤]:接收一条音频(系统音频,格式为ogg),点菜单键选择View slideshow [测试结果]:不能播放,提示是否导入vCard [预期结果]:可以播放 [备注]:附lo ...

  3. winform 窗体换皮肤,IrisSkin2.dll的用法

    1. 先把IrisSkin2.dll文件添加到当前项目引用(解决方案资源管理器->当前项目->引用->右键->添加引用,找到IrisSkin2.dll文件.....之后就不用我 ...

  4. 基础练习 Huffuman树

     基础练习 Huffuman树   时间限制:1.0s   内存限制:512.0MB        问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给 ...

  5. 阿里、华为、腾讯Java技术面试题精选

    阿里.华为.腾讯Java技术面试题精选 2017-10-27 19:30技术/腾讯/华为 JVM的类加载机制是什么?有哪些实现方式? 类加载机制: 类的加载指的是将类的.class文件中的二进制数据读 ...

  6. Python模块 实现过渡性模块重载

    本文是在阅读Python 学习手册后  感觉比较不错的一个实现模块重载的一个模块,该模块可以实现对已经加载在运行程序中的模块实现重新加载,并且该模块可以递归的实现对要重新加载的模块内所引用的其它模块的 ...

  7. ElasticSearch(十):springboot集成ElasticSearch集群完成数据的增,删,改

    前言 之前介绍了使用devTools进行索引库数据的crud,这里使用的是java程序,使用中间件activeMQ进行数据库和索引库数据的同步.主要是用来完成对数据库的修改来完成对索引库的同步. 正文 ...

  8. 大家一起做训练 第一场 E Number With The Given Amount Of Divisors

    题目来源:CodeForce #27 E 题目意思和题目标题一样,给一个n,求约数的个数恰好为n个的最小的数.保证答案在1018内. Orz,这题训练的时候没写出来. 这道题目分析一下,1018的不大 ...

  9. HDU 4638 树状数组 想法题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4638 解题思路: 题意为询问一段区间里的数能组成多少段连续的数.先考虑从左往右一个数一个数添加,考虑当 ...

  10. (1)什么是socket(套接字)

    什么是套接字socket socket把传输层以下的协议都封装成了简单的接口,我编写基于网络通信的软件只需要调用这些接口即可,写出的程序自然是遵循tcp/udp协议的.... 什么是互联网 互联网=物 ...