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. iOS开发多线程篇—GCD简介

    iOS开发多线程篇—GCD介绍 一.简单介绍 1.什么是GCD? 全称是Grand Central Dispatch,可译为“牛逼的中枢调度器” 纯C语言,提供了非常多强大的函数 2.GCD的优势 G ...

  2. ssh key建立后不能clone问题

    在建立了ssh密钥对之后,要将私钥添加,公钥key添加到gitlab的ssh keys里. 添加成功后,这个时候,你可以clone了! 总结:如果是遇到重复输入密码的情况,可能是ssh-key,的私钥 ...

  3. (树莓派、Arduino、物联网、智能家居、机器人)传感器、机械装置、电子元件

    定制 PCB 1. 机械类 履带底盘 2. 传感器 温度传感器(temperature).湿度传感器(humidity) DHT11/DHT22 驱动:BCM2835 (被动)红外传感器(Passiv ...

  4. 清除的通用样式 css

    /*公共样式--开始*/ html, body, div, ul, li, h1, h2, h3, h4, h5, h6, p, dl, dt, dd, ol, form, input, textar ...

  5. stm32 定时器TIM时钟步骤

    1)TIM3 时钟使能 . RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIMx, ENABLE); //时钟使能 2) 初始化定时器参数,设置自动重装值, 分频系数, ...

  6. ElasticSearch(六):IK分词器的安装与使用IK分词器创建索引

    之前我们创建索引,查询数据,都是使用的默认的分词器,分词效果不太理想,会把text的字段分成一个一个汉字,然后搜索的时候也会把搜索的句子进行分词,所以这里就需要更加智能的分词器IK分词器了. 1. i ...

  7. 了解 .NET 的默认 TaskScheduler 和线程池(ThreadPool)设置,避免让 Task.Run 的性能急剧降低

    .NET Framework 4.5 开始引入 Task.Run,它可以很方便的帮助我们使用 async / await 语法,同时还使用线程池来帮助我们管理线程.以至于我们编写异步代码可以像编写同步 ...

  8. hdu1069 dp

    题意:有若干种不同规格(长.宽.高)的砖块,每种砖块有无数个,可以自由选择以砖块的哪条边做长.宽或高,用这些砖块搭高塔,要求上面砖块的长宽必须严格小于下面砖块的长宽,问塔最高能有多高 我的做法是每读入 ...

  9. Android和Linux下设备节点的创建笔记

    1. Linux kernel创建的/dev/下的设备节点是不对的, 其实是kernel仅负责在/sys/(基于内存的虚拟文件系统)创建一大堆下目录和文件,而真正的设备节点是在用户空间程序创建的,应该 ...

  10. Uboot启动命令使用

    1.查看根文件系统中的内容 打断Uboot的启动,默认从SD卡启动,查看根文件系统中/boot下的内容(根文件系统在mmcblk0p1上):=> mmc rescan=> ext4ls m ...