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. 《操作系统_时间片轮转RR进程调度算法》

    转自:https://blog.csdn.net/houchaoqun_xmu/article/details/55540250 时间片轮转RR进程调度算法 一.概念介绍和案例解析时间片轮转法 - 基 ...

  2. 将一个符合URL格式的字符串变成链接

    function replaceURLWithHTMLLinks(text) { /* Example: >>> GateOne.Utils.replaceURLWithHTMLLi ...

  3. Python数据类型补充1

    一.可变和不可变类型 可变类型: 值变了,但是id没有变,证明没有生成新的值而是在改变原值,原值是可变类型 不可变类型:值变了,id也跟着变,证明是生成了新的值而不是在改变原值,原值是不可变 # x= ...

  4. Linux 命令之mv

    mv命令也是Linux中很常见命令 作用:可以用来移动文件或者将文件改名 命令格式: mv [选项] 源文件或目录 目标文件或目录 命令参数: -b :若需覆盖文件,则覆盖前先行备份. -f :for ...

  5. 蚂蚁金服×西安银行 | 西安银行手机银行App的智能升级之路

    小蚂蚁说: 当前,数字化信号已经逐渐深入到社会的每个角落,影响着用户的心智和行为,来到数字化时代门口的银行,需要注意到数字化信号.西安银行通过引入蚂蚁金服移动开发平台mPaaS,对手机银行进行架构升级 ...

  6. activity 运行流程图

  7. rtrim

    <?php $str = '14岁'; $new_str = rtrim($str, '岁'); echo $new_str; 如果右边是'岁',就过滤掉.

  8. Python 模块(module)

    模块(module)也是为了同样的目的.在Python中,一个.py文件就构成一个模块.通过模块,你可以调用其它文件中的程序. first.py def laugh(): print "Ha ...

  9. Python缩进与if语句 空格的魅力

    缩进 Python最具特色的是用缩进来标明成块的代码.我下面以if选择结构来举例.if后面跟随条件,如果条件成立,则执行归属于if的一个代码块. 先看C语言的表达方式(注意,这是C,不是Python! ...

  10. MySQL学习(九)

    1 一道面试题 新建两张表 mysql> create table m -> ( -> mid int, -> hid int, -> gid int, -> mr ...