PAT 甲级 1003 Emergency
发布日期:2021-07-01 03:08:40 浏览次数:2 分类:技术文章

本文共 2730 字,大约阅读时间需要 9 分钟。

1003 Emergency (25 point(s))

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, C​1​​ and C​2​​ - 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 c​1​​, c​2​​ 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 C​1​​ to C​2​​.

Output Specification:

For each test case, print in one line two numbers: the number of different shortest paths between C​1​​ and C​2​​, 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 21 2 1 5 30 1 10 2 20 3 11 2 12 4 13 4 1

Sample Output:

2 4

Experiential Summing-up

This question is a classical dijkstra algorithm involve point weight , edge weight and quantity of short distance.  Nothing else. 

(The purpose of using English to portray my solution is that to exercise the ability of my expression of English and accommodate PAT advanced level's style.We can make progress together by reading and comprehending it. Please forgive my basic grammar's and word's error. Of course, I would appreciated it if you can point out my grammar's and word's error in comment section.( •̀∀•́ ) Furthermore, Big Lao please don't laugh at me because I just a English beginner settle for CET6    _(:з」∠)_  )

Accepted Code

#include 
#include
#include
using namespace std;const int maxn=510;const int INF=0x3fffffff;int g[maxn][maxn],d[maxn],C[maxn],c[maxn],num[maxn],n;bool flag[maxn];void Dijkstra(int s){ fill(d,d+maxn,INF); memset(c,0,sizeof(c)); memset(flag,0,sizeof(flag)); memset(num,0,sizeof(num)); d[s]=0; c[s]=C[s]; num[s]=1; for(int i=0;i
c[v]) { c[v]=c[u]+C[v]; } num[v]+=num[u]; } } } }}int main(){ int m,c1,c2,a,b,v; scanf("%d %d %d %d",&n,&m,&c1,&c2); for(int i=0;i

 

转载地址:https://meteorrain.blog.csdn.net/article/details/86511825 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:PAT 甲级 1004 Counting Leaves
下一篇:PAT 甲级 1002 A+B for Polynomials

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月17日 09时16分12秒