PAT 1003 Emergency
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, 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, c2and 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 Specification:
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
#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的更多相关文章
- PAT 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- PAT 1003 Emergency[图论]
1003 Emergency (25)(25 分) As an emergency rescue team leader of a city, you are given a special map ...
- PAT 1003 Emergency 最短路
As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...
- 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 ...
- PAT 1003. Emergency 单源最短路
思路:定义表示到达i的最短路径数量,表示到达i的最短径,表示最短路径到达i的最多人数,表示从i到j的距离, 表示i点的人数.每次从u去更新某个节点v的时候,考虑两种情况: 1.,说明到达v新的最短路径 ...
- PAT甲级1003. Emergency
PAT甲级1003. Emergency 题意: 作为一个城市的紧急救援队长,你将得到一个你所在国家的特别地图.该地图显示了几条分散的城市,连接着一些道路.每个城市的救援队数量和任何一对城市之间的每条 ...
- 图论 - PAT甲级 1003 Emergency C++
PAT甲级 1003 Emergency C++ As an emergency rescue team leader of a city, you are given a special map o ...
- PAT (Advanced Level) Practise 1003 Emergency(SPFA+DFS)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
随机推荐
- 【译】第18节---数据注解-ForeignKey
原文:http://www.entityframeworktutorial.net/code-first/foreignkey-dataannotations-attribute-in-code-fi ...
- repr() 和 str() 函数
这两个函数都是可以用来将值转换成字符串的. 函数str() 用于将值转化为适于人阅读的形式,而repr() 转化为供解释器读取的形式. 结果是:
- 1 --- Vue 基础指令
1.vue 指令 1.v-model 主要在表单中使用,文本框.teaxare.单选.下拉 等 2.v-text 文本渲染 类似{{}} 3.v-show 控制Dom显示隐藏 displ ...
- Python cmd中输入'pip' 不是内部或外部命令,也不是可运行的程序或批处理文件。
配置一下环境变量,找到 添加一下Scripts文件夹的路径,如:这是我的路径C:\Users\ck\AppData\Local\Programs\Python\Python36 就是你python的安 ...
- C++ 复习要点、面试常见问题总结
本文总结一下C++面试时常遇到的问题.C++面试中,主要涉及的考点有: 关键字极其用法,常考的关键字有const, sizeof, typedef, inline, static, extern, n ...
- 原创:R包制作--windows
1.下载安装Rtools,添加环境变量: 打开R,分别输入下面指令,看有无包错: system('g++ -v') system('where make') 2.package.skeleton()函 ...
- 【Python】【socket】
[server.py] """#练习1import socketimport threading sock = socket.socket()sock.bind(('12 ...
- Broken Keyboard (a.k.a. Beiju Text) 思路
问题:You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem ...
- hdu 2108 Shape of HDU 判断是否为凸多边形
Shape of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- svn的使用教程
引言:这里只讲解几个svn不常用但是非常有用的使用方法,对于经常使用的不做概述,因为很简单,而且网上都能找到. 1.1 svn历史版本对比已经恢复到指定版本(myeclipse) 在项目中的文件或者文 ...