1003 Emergency (25 分)
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 (≤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 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
分析:水题。。Dijkstra模板套上就OK了,另外增加第二标尺、第三标尺时,初始化不能忘!
/**
* Copyright(c)
* All rights reserved.
* Author : Mered1th
* Date : 2019-02-22-17.23.41
* Description : A1003
*/
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<map>
#include<vector>
#include<set>
using namespace std;
;
;
int n,m,st,ed;
},w[maxn]={};
bool vis[maxn]={false};
void Dijkstra(int s){
fill(d,d+maxn,INF);
d[s]=;
w[s]=weight[s];
num[s]=; //这里初始化不能忘记!
;i<n;i++){
,MIN=INF;
;j<n;j++){
if(vis[j]==false && d[j]<MIN){
u=j;
MIN=d[j];
}
}
) return;
vis[u]=true;
;v<n;v++){
if(G[u][v]!=INF && vis[v]==false){
if(d[u]+G[u][v]<d[v]){
d[v]=d[u]+G[u][v];
num[v]=num[u];
w[v]=w[u]+weight[v];
}
else if(d[u]+G[u][v]==d[v]){
if(w[v]<w[u]+weight[v]){
w[v]=w[u]+weight[v];
}
num[v] += num[u]; //最短路径条数与点权无关,写在外面!
}
}
}
}
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif
cin>>n>>m>>st>>ed;
fill(G[],G[]+maxn*maxn,INF);
;i<n;i++){
scanf("%d",&weight[i]);
}
int a,b,t;
;i<m;i++){
scanf("%d%d%d",&a,&b,&t);
G[a][b]=G[b][a]=t;
}
Dijkstra(st);
printf("%d %d\n",num[ed],w[ed]);
;
}
1003 Emergency (25 分)的更多相关文章
- 1003 Emergency (25分) 求最短路径的数量
1003 Emergency (25分) As an emergency rescue team leader of a city, you are given a special map of ...
- 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 ...
- 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 (25 分)(SPFA,DFS)
题意:n个点,m条双向边,每条边给出通过用时,每个点给出点上的人数,给出起点终点,求不同的最短路的数量以及最短路上最多能通过多少人.(N<=500) AAAAAccepted code: #in ...
- PAT 解题报告 1003. Emergency (25)
1003. Emergency (25) As an emergency rescue team leader of a city, you are given a special map of yo ...
- 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 ...
- 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 ...
- PAT 甲级 1003. Emergency (25)
1003. Emergency (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
- 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 ...
随机推荐
- 201621123010《Java程序设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 源代码阅读:多线程程序BounceThread 1.1 BallR ...
- C++基础:什么是命名空间
命名空间是类的逻辑分组,它组织成一个层次结构——逻辑树.这个树的根是System.名字空间是为了防止名字污染在标准C++中引入的.它可以将其中定义的名字隐藏起来,不同的名字空间中可以有相同的名字而互不 ...
- 开源项目ScriptGate,Delphi与JavaScript相互调用的神器
ScriptGate是一个实现TWebBrowser上的JavaScript和Delphi代码相互调用的库,具体在这里:https://bitbucket.org/freeonterminate/sc ...
- 12个有趣的 XSS Vector
XSS Vector #1 <script src=/〱20.rs></script> URL中第二个斜杠在Internet Explorer下(测试于IE11)可被U+303 ...
- MAC中安卓开发环境的下载
今天终于为我的Macbook Pro Retina搭建好了Android开发环境,几经折磨,差点放弃了: 总结如下:1.最好选择ADT Bundle,这里面已经集成好了Eclipse.ADT.Andr ...
- 【linux基础】区块选择VisualBlock
前言 有时候使用linux需要选择某一块区域进行处理,比如对某些列的某些行,类似于Ultraedit的列模式,其实vim中就有相关的功能,此时可以使用vim的区块选择进行处理. 区块选择 1.在一般模 ...
- vec2d
namespace : cv::vec2d; void src2ipm(cv::Mat &srcimage, cv::Mat& uvgrid, cv::Mat& outimag ...
- chapter02 PCA主成分分析在手写数字识别分类的应用
#coding=utf8 # 导入numpy工具包. import numpy as np # 导入pandas用于数据分析. import pandas as pd from sklearn.met ...
- [LeetCode&Python] Problem 637. Average of Levels in Binary Tree
Given a non-empty binary tree, return the average value of the nodes on each level in the form of an ...
- 51Nod 1066:Bash游戏 (巴什博弈)
1066 Bash游戏 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次最少拿1颗,最多拿K颗,拿到 ...