1003. Emergency (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - 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, c2 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 C1 to C2.

Output

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
题意:寻找两点最短路的数量以及所有最短路中的权重和的最大值。
思路:dfs深搜。
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<set>
#include<queue>
#include<cmath>
#include<vector>
#include<bitset>
#include<string>
#include<queue>
#include<cstring>
#include<cstdio>
#include <climits>
using namespace std;
#define INF 0x3f3f3f3f
const int N_MAX = +;
int N, M, from, to;
int dis[N_MAX][N_MAX];
bool vis[N_MAX];
int num[N_MAX];
int Distance;//记录最短距离
int cnt;//记录最短路的条数
int max_amou;
void init() {
for (int i = ; i < N; i++) {
for (int j = ; j < N;j++) {
dis[i][j] = INT_MAX;
}
}
} void dfs(int cur,const int end,int dist,int amou) {//amou是团队数,dist是源点当前点的距离
if (cur == end) {//当前如果走到了终点
if (Distance > dist) {//找到了更短的路
cnt= ;
Distance = dist;
max_amou = amou;
}
else if (Distance==dist) {
cnt++;
if(amou>max_amou)
max_amou = amou;
}
return;
}
if (dist > Distance)return;//如果距离已经超过了最小距离不用继续搜索 for (int i = ; i < N;i++) {
if (!vis[i]&&dis[cur][i]!=INT_MAX) {
vis[i] = true;
dfs(i,end,dist+dis[cur][i],amou+num[i]);
vis[i] = false;
}
}
} int main() {
scanf("%d%d%d%d", &N, &M, &from, &to);
memset(num, , sizeof(num));
memset(vis, , sizeof(vis));
init();
Distance = INT_MAX;
cnt = ;
for (int i = ; i < N; i++) {
scanf("%d",&num[i]);
}
for (int i = ; i < M;i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if (c < dis[a][b]) {
dis[a][b] = c;
dis[b][a] = dis[a][b];
}
}
dfs(from, to, , num[from]);
printf("%d %d\n",cnt,max_amou); return ;
}

PAT 甲级 1003. Emergency (25)的更多相关文章

  1. PAT 甲级1003 Emergency (25)(25 分)(Dikjstra,也可以自己到自己!)

    As an emergency rescue team leader of a city, you are given a special map of your country. The map s ...

  2. PAT甲级1003. Emergency

    PAT甲级1003. Emergency 题意: 作为一个城市的紧急救援队长,你将得到一个你所在国家的特别地图.该地图显示了几条分散的城市,连接着一些道路.每个城市的救援队数量和任何一对城市之间的每条 ...

  3. 图论 - PAT甲级 1003 Emergency C++

    PAT甲级 1003 Emergency C++ As an emergency rescue team leader of a city, you are given a special map o ...

  4. PAT 甲级 1003 Emergency

    https://pintia.cn/problem-sets/994805342720868352/problems/994805523835109376 As an emergency rescue ...

  5. PAT Advanced 1003 Emergency (25) [Dijkstra算法]

    题目 As an emergency rescue team leader of a city, you are given a special map of your country. The ma ...

  6. PAT 解题报告 1003. Emergency (25)

    1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...

  7. PAT 1003. Emergency (25)

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  8. PAT 1003. Emergency (25) dij+增加点权数组和最短路径个数数组

    1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  9. 1003 Emergency (25)(25 point(s))

    problem 1003 Emergency (25)(25 point(s)) As an emergency rescue team leader of a city, you are given ...

随机推荐

  1. C10 C语言数据结构

    目录 枚举 结构体 共用体 枚举 enum enum枚举是 C 语言中的一种基本数据类型,它可以让数据更简洁,更易读. 枚举语法定义格式为: enum 枚举名 {枚举元素1,枚举元素2,……}; 枚举 ...

  2. ctDNA|endosymbiosis

    5.10叶绿体基因组编码多种蛋白质和RNA 叶绿体和线粒体的共同点:叶绿体和线粒体的大小,功能(编码区)大体一致,但叶绿体拥有更多基因,所以在编码tRNA时,也有内含子作为被剪切片段. 因为在原核生物 ...

  3. c++作业:输入两个整数,用函数求两数之和。函数外部声明有什么作用?

    #include <iostream> using namespace std; int main(){ //求两数的和? int a,b,s; cout<<"请你输 ...

  4. linux更新git

    在CentOS中使用yum install git安装的git是1.7版本的,所以需要更新1.9以及更高版本的git. 安装方法如下: 1.安装依赖的包: yum -y install curl-de ...

  5. Ping 命令的执行过程和应用协议

    1. ICMP是“Internet Control Message Ptotocol”的缩写.它是TCP/IP协议族的一个子协议,用于在IP主机.路由器之间传递控制消息. 控制消息是指网络通不通.主机 ...

  6. spring bean的介绍以及xml和注解的配置方法

    5.Bean 下边我们来了解一下Bean的: Bean的作用域Bean的生命周期Bean的自动装配Resources和ResourceLoader 5.1Bean容器的初始化 Bean容器的初始化 两 ...

  7. docker镜像下载

    获得CentOS的Docker CE 预计阅读时间: 10分钟 要在CentOS上开始使用Docker CE,请确保 满足先决条件,然后 安装Docker. 先决条件 Docker EE客户 要安装D ...

  8. salt 模板

    http://www.mamicode.com/info-detail-2297406.html

  9. leetcode-20-Dynamic Programming

    303. Range Sum Query - Immutable 解题思路: Note里说sumRange会被调用很多次..所以简直强烈暗示要做cache啊...所以刚开始,虽然用每次都去遍历数组求和 ...

  10. OverflowError:django signed integer is greater than maximum

    在学习一对一查询的时候,打印作者的电话时报了这个错 alex = Author.objects.filter(name='alex').first() print(alex.authordetail. ...