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
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
提交代码

更多源码详见:https://github.com/Azure-Sky-L/PAT

DFS

代码:

#include<cstdio>
#include<vector>
using namespace std;
struct node{int b,c;
};
vector <node> v[510];
int t[510],vis[510],n,m,e,s,sum = 0,ans = 0,ss = 0x3f3f3f3f;
void dfs(int p,int cut,int mt){int pp = mt + t[p],ww;if(p == e){if(ss > cut) ss = cut,sum = 1,ans = pp;else if(ss == cut) sum++,ans = max(pp,ans);return ;}vis[p] = 1;for(int i = 0; i < v[p].size(); i++){int o = v[p][i].b;if(!vis[o])ww = cut + v[p][i].c,dfs(o,ww,pp);}vis[p] = 0;
}
int main()
{scanf("%d %d %d %d",&n,&m,&s,&e);for(int i = 0; i < n; i++)scanf("%d",&t[i]);while(m--){int a,b,c;scanf("%d %d %d",&a,&b,&c);node o;o.b = b,o.c = c;v[a].push_back(o);o.b = a;v[b].push_back(o);}dfs(s,0,0);printf("%d %d\n",sum,ans);return 0;
}

PAT(甲级) 1003. Emergency相关推荐

  1. PAT甲级1003 Emergency:[C++题解]dijkstra求最短路、最短路条数

    文章目录 题目分析 题目链接 题目分析 分析:求单源最短路,使用dijkstra()算法. 最短路的条数,和最短路中 人数最多的一条,输出最多人数. 本题点比较少,使用邻接矩阵d[N][N]来存. a ...

  2. PAT甲级 1003 Emergency

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

  3. PAT甲级1003 Emergency Dijkstra算法(堆优化版/朴素版)

    前言   最近花了很多的时间在写JAVA项目上面,疏忽了算法和数据结构的学习.最近突然醒悟基础更为重要,打算从今天开始每天抽出一些时间做下PAT甲级的题目.现有题库的前两题很简单,从第三题开始吧. 题 ...

  4. PAT 甲级1003 Emergency 题解

    在PAT1003 Emergency 这道题上上卡了很久,多次修改考虑漏掉的Case后,成功解决问题. 题目描述 每个输入文件包含一个测试用例. 对于每个测试用例,第一行包含4个正整数:N(≤500) ...

  5. PAT甲级 1003 Emergency 单源Dijkstra最短路

    Solution: 这道题的意思是给定起点和终点,求最短路.但还有一个要求,就是每个城市有救援队,我们要在求得最短路的情况下集结沿途尽可能多的救援队人数. 这道题的n值较小,直接dijkstra即可. ...

  6. (迪杰斯特拉)Dijkstra算法详解 PAT甲级 1003

    1.迪杰斯特拉(Dijkstra)算法介绍 迪杰斯特拉(Dijkstra)算法是典型最短路径算法,用于计算一个节点到其他节点的最 短路径. 它的主要特点是以起始点为中心向外层层扩展(广度优先搜索思想) ...

  7. 【PAT - 甲级1003】Emergency (25分)(Dijkstra,最短路条数,双权值最短路)

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

  8. PAT 甲级 1003

    PAT 1003 题目介绍: 给出城市的连接状况和每个城市的救援队伍的数量.给定起点和终点,求出起点到终点最短路径的个数,以及找出一条可以包含救援队最多的最短路径,输出最多可以累计的救援队的数目. 题 ...

  9. PAT甲级 1003 Dijkstra的口诀干货

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

最新文章

  1. 我都惊了这么多年pytorch还可以这么用
  2. tensorflow中的placeholder()
  3. Vue学习笔记第一天--es6
  4. python不可变的列表被称为_【Python学习】可变类型和不可变类型
  5. bootstrapV4.6.0 图片宫格布局(案例篇)
  6. ext4.0 代理 的使用
  7. 喜大普奔:我的个人博客www.yxmblog.top
  8. mysql 5.7.29下载安装_deepin20 离线安装 MySQL5.7.29
  9. kuka机器人外部轴异步_KUKA机器人外部轴标准配置
  10. python魅力_Python逐渐失去魅力
  11. C#动态创建和动态使用程序集、类、方法、字段等(二)
  12. 深度学习 DEEP LEARNING 1-2章
  13. html行内样式选择器怎么写,巧用CSS伪类选择器实现九种样式的九宫格
  14. Java接口测试工具rap_接口文档管理工具-Postman、Swagger、RAP(转载)
  15. 品高云暴漫 | 云计算足球赛之黑马
  16. 200卡拨号上网设置
  17. React中CodeMirror插件的使用及封装
  18. invalid token XXX
  19. 【解决方案】GB28181/RTSP/SDK/Ehome协议支持级联视频智能分析平台EasyCVR如何搭建小区/园区视频监控系统
  20. 三级等保要求及所需设备

热门文章

  1. Day14:网络编程入门
  2. Jmeter 中断言操作
  3. fpga实操训练(一个典型的fpga系统)
  4. 8086CPU结构与功能
  5. 一起作业网 肖盾:如何打动投资人,说服老师,造福学生
  6. 引力魔方的特性和玩法
  7. word 插入图片显示不全
  8. Consul Sessions
  9. java jsoup jar包_jsoup jar包
  10. 区块链开发先达区块链跨境支付系统解决方案