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. 文档对象模型DOM

    文档对象模型 DOM 1 DOM概述 1.1 什么是DOM 文档对象模型 Document Object Model 提供给用户操作document obj 的标准接口 文档对象模型 是表示和操作 H ...

  2. shell中的${},##, %% , :- ,:+, ? 的使用

    假设我们定义了一个变量为:file=/dir1/dir2/dir3/my.file.txt 可以用${ }分别替换得到不同的值:${file#*/}:删掉第一个/ 及其左边的字符串:dir1/dir2 ...

  3. _equipment

    该表控制切换地图自动更换装备,离开该地图时,装备自动切换为原来.,HEAD - TABARD小于0时取下装备,等于0时不更换,大于0时更换为对应装备. comment 备注 class 职业索引 1- ...

  4. 初步接触ES6

    Babel---ES6转码器 ES6 声明变量的六种方法 ES5 只有两种声明变量的方法:var命令和function命令. ES6除了添加let和const命令,另外两种声明变量的方法:import ...

  5. WebSocket 教程

    转载自:http://www.ruanyifeng.com/blog/2017/05/websocket.html WebSocket 是一种网络通信协议,很多高级功能都需要它. 本文介绍 WebSo ...

  6. python发送requests请求时,使用登录的token值,作为下一个接口的请求头信息

    背景介绍: 发送搜索请求时,需要用到登录接口返回值中的token值 代码实现: 登录代码: 搜索接口:

  7. Eclipse使用之将Git项目转为Maven项目, ( 注意: 最后没有pom.xml文件的, 要转化下 )

    Eclipse使用之将Git项目转为Maven项目(全图解) 2017年08月11日 09:24:31 阅读数:427 1.打开Eclipse,File->Import 2.Git->Pr ...

  8. 《剑指offer》第五十六题(数组中只出现一次的两个数字)

    // 面试题56(一):数组中只出现一次的两个数字 // 题目:一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序 // 找出这两个只出现一次的数字.要求时间复杂度是O(n),空间复杂度 ...

  9. Android 虹软免费人脸识别App

    人脸识别+本机Web后端 人脸sdk采用虹软sdk,本机web采用AndServer:上传姓名+人脸图片即可实现注册源码地址:https://github.com/joetang1989/ArcFac ...

  10. Linux Ubuntu下用Android NDK 生成独立交叉编译链

    本文主要介绍使用Android NDK生成独立交叉编译链,然后使用独立交叉编译链编译Android程序 下载NDK 下载与自己操作系统相吻合的版本 下载地址 解压到安装目录(如~/myndk): ta ...