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. Bzoj 3450: Tyvj1952 Easy (期望)

    Bzoj 3450: Tyvj1952 Easy 这里放上题面,毕竟是个权限题(洛谷貌似有题,忘记叫什么了) Time Limit: 10 Sec Memory Limit: 128 MB Submi ...

  2. 【AC自动机】bzoj3172: [Tjoi2013]单词

    fail图上后缀和需要注意一下 Description 某人读论文,一篇论文是由许多单词组成.但他发现一个单词会在论文中出现很多次,现在想知道每个单词分别在论文中出现多少次. Input 第一个一个整 ...

  3. k8s的资源限制及资源请求

    容器的资源需求及限制:  需求:requests   ##定义容器运行时至少需要资源  限制:limits     ##定义容器运行时最多能分配的资源    requests:pod.spec.con ...

  4. python-类与继承

    类的继承 什么是继承? 继承是一种新建类的方式,新建的类称为子类,被继承的类称为父类.python中,父类.子类(派生类)只有在继承的时候才会产生. 继承的特性:子类会继承父类所有的属性. 为什么要用 ...

  5. solr配置中文分词器

    配置IK分词器 在/opt/solr-7.7.1/server/solr-webapp/webapp/WEB-INF/lib目录中加入IK分词器的jar包 在/opt/solr-7.7.1/serve ...

  6. LeetCode(138) Copy List with Random Pointer

    题目 A linked list is given such that each node contains an additional random pointer which could poin ...

  7. 【HIHOCODER 1055】 刷油漆(树上背包)

    描述 小Ho有着一棵灰常好玩的树玩具!这棵树玩具是由N个小球和N-1根木棍拼凑而成,这N个小球都被小Ho标上了不同的数字,并且这些数字都是处于1..N的范围之内,每根木棍都连接着两个不同的小球,并且保 ...

  8. HTTP认证之基本认证——Basic(一)

    导航 HTTP认证之基本认证--Basic(一) HTTP认证之基本认证--Basic(二) HTTP认证之摘要认证--Digest(一) HTTP认证之摘要认证--Digest(二) 一.概述 Ba ...

  9. Shell脚本完成hadoop的集群安装

    虽然整体实现的自动安装,但还是有很多需要完善的地方,比如说: 1. 代码目前只能在root权限下运行,否则会出错,这方面需要加权限判断: 2.另外可以增加几个函数,减少代码冗余: 3.还有一些判断不够 ...

  10. python - 文件处理/open

    # -*- coding:utf-8 -*- '''@project: jiaxy@author: Jimmy@file: study_文件处理.py@ide: PyCharm Community E ...