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. C#数组简介

    一.数组的定义 数组:是一种包含若干个变量的数据结构,这些变量可以通过索引进行访问. 数组的元素:数组中的变量就称为数组的元素. 元素类型:数组中的元素具有相同的数据类型,该数据类型就称为数组的元素类 ...

  2. C#数组排序方法

    在C#中常用的数组排序的方法有:选择排序法.冒泡排序法.插入排序法和希尔排序法等. 一.选择排序法 using System;using System.Collections.Generic;usin ...

  3. 01_11_SERVLET中使用javabean

    01_11_SERVLET中使用javabean 1. javabean 广义javabean = 普通java类 狭义javabean = 符合 Sun JavaBean标准的类 在Servlet中 ...

  4. 01_3Java Application初步

    01_3Java Application初步 l Java源文件以“java”为扩展名.源文件的基本组成部分是类(class),如本例中的HelloWorld类. l 一个源文件中最多只有一个publ ...

  5. 酷炫的3D照片墙

    今天给大家分享的案例是酷炫的3D照片墙 这个案例主要是通过 CSS3 和原生的 JS 来实现的,接下来我给大家分享一下这个效果实现的过程.博客上不知道怎么放本地视频,所以只能放两张效果截图了. 1.实 ...

  6. OI杂记

    从今天开始记录一下为数不多天的OI历程 8.25 上 今天举行了难得的五校联考,模拟noip,题目的解压密码竟然是$aKnoIp2o18$,对你没有看错!!! 7:50老师?啊啊啊啊,收不到题目啊,还 ...

  7. 关于bc中小数点length,scale,(())以及进制转换

    这是我在codewar上遇到的一个题,我用我自己的方法做出了解答,如下: 1 #!/bin/bash 2 3 distance=`echo "$1*10000"|bc|cut -d ...

  8. charles 模拟手机弱网、修改请求参数、修改返回值

    1.charles模拟弱网(断网) 2.charles修改请求参数 (1)先访问一次需要改的请求,在charles上找到相应的请求地址 (2)然后在需要打断点的请求上右键,勾选[Breakpoints ...

  9. Hibernate知识梳理

    一.SessionFactory接口 是单个数据库映射关系(ORM)经过编译后的内存镜像.SessionFactory(的实例)作为应用中的一个全局对象(工厂),可以随处打开/创建一个session, ...

  10. Python 基本数据类型 (二) - 字符串1

    # ----------- 首字母大写 ---------- test = "alex is a man" v = test.capitalize() print(v): Alex ...