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 (≤) - 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:

  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<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int mp[][] = {};
  5. int vis[] = {};
  6. int chenshi,daolu,start,over;
  7. int val[] = {};
  8. int cnt=;
  9. int minval = INT_MAX;
  10. int maxnum = INT_MIN;
  11.  
  12. void dfs(int x,int nowval,int nownum){
  13. if(x == over){
  14. if(nowval < minval){minval = nowval;cnt=;maxnum = nownum;}
  15. else if(nowval == minval){cnt++;maxnum = max(maxnum,nownum);}
  16. return;
  17. }
  18.  
  19. for(int i=;i < chenshi;i++){
  20. if(!vis[i]&&mp[x][i]){
  21. vis[i] = ;
  22. dfs(i,nowval+mp[x][i],nownum+val[i]);
  23. vis[i] = ;
  24. }
  25. }
  26.  
  27. return;
  28. }
  29.  
  30. int main(){
  31.  
  32. cin >> chenshi >> daolu >> start >> over;
  33. vis[start] = ;
  34.  
  35. for(int i=;i < chenshi;i++) cin >> val[i];
  36.  
  37. while(daolu--){
  38. int i,j,n;
  39. cin >> i >> j;cin >> n;
  40. mp[i][j] = mp[j][i] = n;
  41. }
  42.  
  43. dfs(start,,val[start]);
  44. cout << cnt << " " << maxnum;
  45.  
  46. return ;
  47. }

一发入魂,我太牛逼了。

复习了图的dfs,一开始漏掉了是无向图的条件。

PAT 1003 Emergency的更多相关文章

  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) dij+增加点权数组和最短路径个数数组

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

  3. PAT 1003 Emergency[图论]

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

  4. PAT 1003 Emergency 最短路

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

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

  6. PAT 1003. Emergency 单源最短路

    思路:定义表示到达i的最短路径数量,表示到达i的最短径,表示最短路径到达i的最多人数,表示从i到j的距离, 表示i点的人数.每次从u去更新某个节点v的时候,考虑两种情况: 1.,说明到达v新的最短路径 ...

  7. PAT甲级1003. Emergency

    PAT甲级1003. Emergency 题意: 作为一个城市的紧急救援队长,你将得到一个你所在国家的特别地图.该地图显示了几条分散的城市,连接着一些道路.每个城市的救援队数量和任何一对城市之间的每条 ...

  8. 图论 - PAT甲级 1003 Emergency C++

    PAT甲级 1003 Emergency C++ As an emergency rescue team leader of a city, you are given a special map o ...

  9. PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)

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

随机推荐

  1. Hive初步使用、安装MySQL 、Hive配置MetaStore、配置Hive日志《二》

    一.Hive的简单使用 基本的命令和MySQL的命令差不多 首先在 /opt/datas 下创建数据  students.txt 1001 zhangsan 1002 lisi 1003 wangwu ...

  2. Kubernetes工作流之Pods二

    Init Containers This feature has exited beta in 1.6. Init Containers can be specified in the PodSpec ...

  3. js replace使用及正则表达式使用

    本文为博主原创,未经允许不得转载: js中replace方法与java中的replace方法相同,主要做替换. 表达式:stringObj.replace(rgExp, replaceText) 参数 ...

  4. Javascript 高级程序设计(第3版) - 第01章

    2017-05-10 js简介 一个叫“不难登”的人发明的.js的流行是因为 ajax 的关系. js分为三个部分: 核心: ECMAScript 文档对象模型: DOM 浏览器对象模型: BOM 核 ...

  5. js判断数字、整数、字符串、布尔,特殊方法

    整数: function isInteger(obj) { return Math.floor(obj) === obj } isInteger(3) // true isInteger(3.3) / ...

  6. 2、My Scripts

    http://www.cnblogs.com/image-eye/archive/2011/10/26/2220405.html      注释详解 1.打印选择菜单,按照选择项一键安装不同的web服 ...

  7. Leetcode122-Best Time to Buy and Sell Stock II-Easy

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  8. 【C#】 基于ArcFace 2.0—视频人脸识别Demo

    使用的虹软人脸识别技术 啥话不说,不用跪求,直接给下载地址:http://common.tenzont.com/comdll/arcface2demo.zip(话说附件的大小不限制,还是说我的文件太大 ...

  9. 牛客国庆集训派对Day3 I Metropolis

    Metropolis 思路: 多源点最短路 只要两个不同源点的最短路相遇,我们就更新两个源点的答案 代码: #pragma GCC optimize(2) #pragma GCC optimize(3 ...

  10. Codeforces 101173 C - Convex Contour

    思路: 如果所有的图形都是三角形,那么答案是2*n+1 否则轮廓肯定触到了最上面,要使轮廓线最短,那么轮廓肯定是中间一段平的 我们考虑先将轮廓线赋为2*n+2,然后删去左右两边多余的部分 如果最左边或 ...