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 ...
随机推荐
- CSS sprites
CSS Sprites在国内很多人叫css精灵,是一种网页图片应用处理方式. 优点: 它允许你将一个页面涉及到的所有零星图片都包含到一张大图中去,这样一来,当访问该页面时,载入的图片就不会像以前那样一 ...
- C++中substr函数的用法
#include<iostream> #include<string> using namespace std; int main(){ string str("12 ...
- 一步到位之INNODB
原文链接:http://imysql.com/2012/09/21/mysql-faq-setup-innodb-quickly.html 快速认识InnoDB InnoDB是MySQL下使用最广泛的 ...
- 使用CSS渐变
转载自:https://developer.mozilla.org/zh-CN/docs/Web/Guide/CSS/Using_CSS_gradients CSS 渐变 是在 CSS3 Image ...
- centos7 下载安装tomcat9
需要Java环境 https://www.cnblogs.com/sea-stream/p/10404360.html 官网下载安装包 wget http://archive.apache.org/d ...
- PHP Warning: Module 'memcache' already loaded in Unknown on line 0
出现类似PHP Warning: Module * already loaded in Unknown on line 0,一般是可能因为升级php导致的组件重复加载,解决就是 1.vi /etc/p ...
- label和span的区别
label标签主要用于绑定一个表单元素,当点击label标签的时候,被绑定的表单元素就会获得输入焦点. <div class="form-group col-lg-12"&g ...
- cookie被禁用,如何使用session
转载自:https://blog.csdn.net/ai_shuyingzhixia/article/details/80778183 1.禁止使用cookie response.encodeURL( ...
- Spark多种运行模式
1.测试或实验性质的本地运行模式(单机) 该模式被称为Local[N]模式,是用单机的多个线程来模拟Spark分布式计算,通常用来验证开发出来的应用程序逻辑上是否有问题. 其中N代表可以使用N个线程, ...
- 学习笔记39—笑谈FireFox标签不同步(IOS和Wiindows)
为了解决国内用户连接 全球同步服务器 困难的问题,火狐中国版推出了 全球服务 和 本地服务 两套服务. 这两套服务的账号和数据并不通用,并且只有中国版提供了切换功能,因此当你在同步过程中遇到“未知账号 ...