【C++】1003. Emergency (25)*
来源:互联网 发布:新津知美术馆多少瓦片 编辑:程序博客网 时间:2024/06/10 18:58
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.
5 6 0 21 2 1 5 30 1 10 2 20 3 11 2 12 4 13 4 1Sample Output
2 4
1.关于求图的最小路径算法 ,是最短路径有几条!
2.在自己的城市的话,也是有可能的
1.只通过2个测试点。
#include<iostream>#include<vector>using namespace std;struct ROAD{int L;int to;};std::vector<std::vector<ROAD>> map;int main(){int hh,mm;//freopen("in.txt","r",stdin);int N,M,C1,C2,n,i;while(scanf("%d%d%d%d",&N,&M,&C1,&C2)!=EOF){int nn=C1;int cc=0,max=-1;n=N;int dist[501];//memset(dist,-1,sizeof(int));int rescue[501]={0},cost[501]={0};bool mark[501]={false};for(i=0;i<N;i++){int temp;scanf("%d",&temp);rescue[i]=temp;dist[i]=-1;}map.resize(N);for(i=0;i<M;i++){int c1,c2,len;ROAD aa;scanf("%d%d%d",&c1,&c2,&len);aa.L=len;aa.to=c2;map[c1].push_back(aa);aa.to=c1;map[c2].push_back(aa);}if(C1==C2){cout<<"1 "<<rescue[C1];return 0;}int j;mark[C1]=true;dist[C1]=0;//cost[C1]=rescue[C1];for(i=0;i<N;i++){for(j=0;j<map[nn].size();j++){//int t=map[nn][j].to;int ll=map[nn][j].L;//int co=map[nn][j].cost;if(mark[t]==true){continue;}if(dist[t]==-1||dist[t]>dist[nn]+ll){dist[t]=dist[nn]+ll;cost[t]=rescue[nn]+cost[nn];if(t==C2){cc=1;}}else if(dist[t]==dist[nn]+ll&&cost[t]<cost[nn]+rescue[nn]){cost[t]=rescue[nn]+cost[nn];if(t==C2){cc++;}}}int min=123123123;for(int j=0;j<N;j++){//找出最小的路if(mark[j]==true) continue;if(dist[j]<min&&dist[j]>=0){min=dist[j];nn=j;}}mark[nn]=true;}cout<<cc<<" "<<cost[C2]+rescue[C2];}return 0;}
#define INF 0x6FFFFFFF #include<iostream>#include<vector>using namespace std;struct ROAD{int L;int to;};std::vector<std::vector<ROAD>> map;int main(){int hh,mm;freopen("in.txt","r",stdin);int N,M,C1,C2,n,i;while(scanf("%d%d%d%d",&N,&M,&C1,&C2)!=EOF){int nn=C1;int cc=0,max=-1;n=N;int dist[501];//memset(dist,-1,sizeof(int));int rescue[501]={0},cost[501]={0};bool mark[501]={false};for(i=0;i<N;i++){int temp;scanf("%d",&temp);rescue[i]=temp;dist[i]=-1;}map.resize(N);for(i=0;i<M;i++){int c1,c2,len;ROAD aa;scanf("%d%d%d",&c1,&c2,&len);aa.L=len;aa.to=c2;map[c1].push_back(aa);aa.to=c1;map[c2].push_back(aa);}if(C1==C2){cout<<"1 "<<rescue[C1];return 0;}int j;mark[C1]=true;dist[C1]=0;//cost[C1]=rescue[C1];for(i=0;i<N;i++){for(j=0;j<map[nn].size();j++){//int t=map[nn][j].to;int ll=map[nn][j].L;//int co=map[nn][j].cost;if(mark[t]==true){continue;}if(dist[t]==-1||dist[t]>dist[nn]+ll){dist[t]=dist[nn]+ll;cost[t]=rescue[nn]+cost[nn];if(t==C2){cc=1;}}else if(dist[t]==dist[nn]+ll&&cost[t]<cost[nn]+rescue[nn]){cost[t]=rescue[nn]+cost[nn];if(t==C2){cc++;}}}int min=123123123;for(int j=0;j<N;j++){//找出最小的路if(mark[j]==true) continue;if(dist[j]<min&&dist[j]>=0){min=dist[j];nn=j;}}mark[nn]=true;}cout<<cc<<" "<<cost[C2]+rescue[C2];}return 0;}
- 【C++】1003. Emergency (25)*
- 1003. Emergency (25)[C语言]
- 【PAT甲级】【C++】1003. Emergency (25)
- PAT 1003. Emergency C语言
- 1003. Emergency (25)
- 1003. Emergency (25)-PAT
- (PAT)1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- PAT 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- PAT 1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- [PAT]1003. Emergency (25)
- 1003. Emergency (25)
- 1003. Emergency (25)
- linux 重定向命令
- ios--NSString与const char *转换
- vim 中Ctags的安装和使用
- Linux驱动虚拟地址和物理地址的映射
- Web_XP_IIS_“服务器应用程序不可用”问题;
- 【C++】1003. Emergency (25)*
- 第四周——三角类2
- mosquitto源码分析(一)
- HTC G11自带键盘具有上下左右键,导致不希望的逻辑出现
- JAVA获取一个字符串在整个字符串中出现的次数
- Permission denied
- 今天工作
- C# 系统应用之使用Pancel控件同一窗体切换页面
- CoreData -2