PAT 1003. Emergency (25)

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

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
 1 #include <iostream>
 2 #include <vector>
 3 
 4 using namespace std;
 5 
 6 const int INF = 0x7fffffff;
 7 struct Node
 8 {
 9     bool isknown = false;
10     int minLength = INF;
11 };
12 
13 int rescueTeams[500];
14 int cityMap[500][500];
15 int MaxTeams[500];
16 int minPath[500];
17 Node nodes[500];
18 
19 int main()
20 {
21     int cityNum, roadNum, start, destination;
22 
23     for (int i = 0; i<500; i++)    //initialize the city map
24         for (int j = 0; j<500; j++)
25             cityMap[i][j] = INF;
26 
27     cin >> cityNum >> roadNum >> start >> destination;
28     for (int i = 0; i<cityNum; i++)
29         cin >> rescueTeams[i];
30 
31     //construct the city map
32     for (int i = 0; i<roadNum; i++)
33     {
34         int c1, c2, length;
35         cin >> c1 >> c2 >> length;
36         if (cityMap[c1][c2] > length)
37             cityMap[c1][c2] = cityMap[c2][c1] = length;
38     }
39 
40     //using dijkstra algorithms
41     nodes[start].isknown = true;    //set the start konwn
42     nodes[start].minLength = 0;
43     MaxTeams[start] = rescueTeams[start];
44     minPath[start] = 1;
45     int minNode = start;
46     int cnt = 1;
47     while (cnt < cityNum)
48     {
49         //update the node connnected to the minimum node
50         for (int j = 0; j<cityNum; j++)
51         {
52             if (cityMap[minNode][j] < INF)
53             {
54                 //with a equal length and record the route
55                 if (nodes[minNode].minLength + cityMap[minNode][j] == nodes[j].minLength)
56                 {
57                     if (MaxTeams[j] < MaxTeams[minNode] + rescueTeams[j])
58                         MaxTeams[j] = MaxTeams[minNode] + rescueTeams[j];
59                     minPath[j] += minPath[minNode];
60                 }
61                 //with a smaller length
62                 else if (nodes[minNode].minLength + cityMap[minNode][j] < nodes[j].minLength)
63                 {
64                     nodes[j].minLength = nodes[minNode].minLength + cityMap[minNode][j];
65                     MaxTeams[j] = rescueTeams[j] + MaxTeams[minNode];
66                     minPath[j] = minPath[minNode];
67                 }            
68             }
69         }
70 
71         //find the unkonwn node with the minimum length
72         int minLength = INF;
73         for (int i = 0; i<cityNum; i++)
74         {
75             if (!nodes[i].isknown && minLength > nodes[i].minLength)
76             {
77                 minLength = nodes[i].minLength;
78                 minNode = i;
79             }
80         }
81         nodes[minNode].isknown = true;
82         cnt++;
83     }
84 
85     cout << minPath[destination] << " " << MaxTeams[destination];
86 }

 

转载于:https://www.cnblogs.com/jackwang822/p/4745697.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip
毕设新项目基于python3.7+django+sqlite开发的学生就业管理系统源码+使用说明(含vue前端源码).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 学生就业管理系统(前端) ## 项目开发环境 - IDE: vscode - node版本: v12.14.1 - npm版本: 6.13.4 - vue版本: @vue/cli 4.1.2 - 操作系统: UOS 20 ## 1.进入项目目录安装依赖 ``` npm install ``` ## 2.命令行执行进入UI界面进行项目管理 ``` vue ui ``` ## 3.编译发布包(请注意编译后存储路径) #### PS:需要将编译后的包复制到后端项目的根目录下并命名为'static' 学生就业管理系统(后端) ## 1.项目开发环境 - IDE: vscode - Django版本: 3.0.3 - Python版本: python3.7.3 - 数据库 : sqlite3(测试专用) - 操作系统 : UOS 20 ## 2.csdn下载本项目并生成/安装依赖 ``` pip freeze > requirements.txt pip install -r requirements.txt ``` ## 3.项目MySQL数据库链接错误 [点击查看解决方法](https://www.cnblogs.com/izbw/p/11279237.html)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值