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:

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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int mp[][] = {};
int vis[] = {};
int chenshi,daolu,start,over;
int val[] = {};
int cnt=;
int minval = INT_MAX;
int maxnum = INT_MIN; void dfs(int x,int nowval,int nownum){
if(x == over){
if(nowval < minval){minval = nowval;cnt=;maxnum = nownum;}
else if(nowval == minval){cnt++;maxnum = max(maxnum,nownum);}
return;
} for(int i=;i < chenshi;i++){
if(!vis[i]&&mp[x][i]){
vis[i] = ;
dfs(i,nowval+mp[x][i],nownum+val[i]);
vis[i] = ;
}
} return;
} int main(){ cin >> chenshi >> daolu >> start >> over;
vis[start] = ; for(int i=;i < chenshi;i++) cin >> val[i]; while(daolu--){
int i,j,n;
cin >> i >> j;cin >> n;
mp[i][j] = mp[j][i] = n;
} dfs(start,,val[start]);
cout << cnt << " " << maxnum; return ;
}

一发入魂,我太牛逼了。

复习了图的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. jlink的SWD与JTAG下载模式的对应接线方法

     参考博客:http://blog.csdn.net/qq_26093511/article/details/59484249 (1)如果用jtag模式下载的话需要接线:          jlink ...

  2. (转载)Unity里实现更换游戏对象材质球

    在unity中本来想实现在一个背景墙上更换图片的功能 在网上查了一些资料说是用Image,但我是新手小白刚接触Unity不久好多组建还不会用,就想能不能通过改变游戏对象的材质球来更换游戏对象的背景. ...

  3. 【C#】委托的发展

    "用事件去处理程序, 进而解决问题" ---- 委托的目的 委托早在C#2的时候就已经初具模型, 但是并不是特别灵活, 制止C#3才在代码中被广泛使用. C#4中泛型委托, C#5 ...

  4. 利用C#实现AOP常见的几种方法详解

    利用C#实现AOP常见的几种方法详解 AOP面向切面编程(Aspect Oriented Programming) 是通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. 下面这篇文章主要 ...

  5. Kylin简介

    来源 Cube: 用空间换时间(类似:BI分析) 预计算把用户需要查询的维度以及他们所对应的考量的值,存储在多维空间里 当用户查询某几个维度的时候,通过这些维度条件去定位到预计算的向量空间,通过再聚合 ...

  6. latex建立参考文献的超链接

    在Latex生成的pdf文档中建立超链接(如从正文到参考文献,从目录到相应内容,从页码编号到实际页面等),有利于读者快速定位当前阅读的信息. 如何在生成的pdf文件中包含超链接呢?需要注意一下两点: ...

  7. pymouse 点击指定坐标点

    from pymouse import PyMouse mouse = PyMouse() mouse.click(,)

  8. typeScript入门基础 (2): 数据 类型, 函数定义

    1.   number , boolean, string, null, undefind  枚举, any, array数组, 元祖, 2...枚举,需要的注意点,  下一个图,就是为什么yello ...

  9. maven项目依赖jar包报 java.lang.classnotfoundexception:Type com.xx.xx.xxx not present 的解决

    今天在工作的时候遇到了这样一个奇葩的异常: java.lang.classnotfoundexception:Type com.ys.yahu.vo.file.MobileFileVo not pre ...

  10. 全排列问题Ⅰ(Java实现)

    给定一个没有重复数字的序列,返回其所有可能的全排列. 示例: 输入: [1,2,3] 输出: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1 ...