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 ...
随机推荐
- Swift Tips笔记
“??”操作符可以判断输入并在当左侧的值是非 nil 的 Optional 值时返回其 value,当左侧是 nil 时返回右侧的值. 例: var level: Int? var startLeve ...
- wilber3申请数据的直接目录寻找
ftp://ds.iris.edu/pub/userdata/
- prop和state的区别
1.prop用于定义外部接口,state用于记录内部状态: 2.prop的赋值在外部世界使用组件时,state的赋值在组件内部: 3.组件不应该改变prop的值,但是state的存在目的就是让组件来改 ...
- SWIFT中使用AFNetwroking访问网络数据
AFNetworking 是 iOS 一个使用很方便的第三方网络开发框架,它可以很轻松的从一个URL地址内获取JSON数据. 在使用它时我用到包管理器Cocoapods 不懂的请移步: Cocoapo ...
- HDU 1501 Zipper(DFS)
Problem Description Given three strings, you are to determine whether the third string can be formed ...
- 安装SharePoint Server的主机重命名
今天我头脑一热, 把安装在WS 2008 R2上的有Stand-alone SharePoint Server 2010的机器重命名了一下, 结果SharePoint Central Admin都进不 ...
- 批量解帧视频文件cpp
前言 将多个视频文件进行解帧. 实现过程 1.批量获取文件路径: 2.对某个视频文件进行解帧: 代码 /************************************************ ...
- [LeetCode&Python] Problem 412. Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...
- .NET 之 垃圾回收机制GC
一.GC的必要性 1.应用程序对资源操作,通常简单分为以下几个步骤:为对应的资源分配内存 → 初始化内存 → 使用资源 → 清理资源 → 释放内存. 2.应用程序对资源(内存使用)管理的方式,常见的一 ...
- Ordering Tasks 拓扑排序
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...