博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1003. Emergency
阅读量:6921 次
发布时间:2019-06-27

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

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 21 2 1 5 30 1 10 2 20 3 11 2 12 4 13 4 1
Sample Output
2 4 ac代码:
//注意初始化时将所有e[i][j]所有初始化为max.不需要区分i=j;#include
#include
const int vmax=510;int dist[vmax];int visit[vmax];int n,c1,c2,per,count,maxper;//点数int path[vmax];int distance;//纪录到此结点能招到的人数;typedef struct{ int v[vmax]; int e[vmax][vmax]; int vnumb; int enumb;}graph;void dfs(graph *g,int i){// int ii,jj;// visit[i]=1; if(distance>dist[c2]) return;// per+=g->v[i];// printf("%d\n",i);// int pp; if(i==c2) { if(distance==dist[c2]) { count++; if(maxper
vnumb;ii++) { if(i!=ii&&g->e[i][ii]!=-1&&visit[ii]==0) { per+=g->v[ii]; distance+=g->e[i][ii]; visit[ii]=1; dfs(g,ii); distance-=g->e[i][ii]; visit[ii]=0; per-=g->v[ii]; } }} void dijkstra(graph *g,int i){ int q,p; memset(visit,0,sizeof(visit)); int u=i; visit[u]=1; dist[u]=0;// path[u]=u; for(p=1;p
e[u][q]!=-1&&dist[q]>dist[u]+(g->e[u][q])&&visit[q]==0)//找u,q之间存在边,且q!=u,未被访问,且距离更小 { dist[q]=dist[u]+g->e[u][q]; path[q]=u; } } int minval=9999999;//find the min dist[u];不可以赋初值为dist[0];注意,可能dist[0]就是最小的,就死循环了。; for(q=0;q
vnumb=n; g->enumb=m; for(i=0;i
e[i][j]=-1; else g->e[i][j]=0; } for(i=0;i
v[i]); } for(i=0;i
e[j][k]=t; g->e[k][j]=t; }/*for(i=0;i
e[i][j]); } printf("\n");}*/ dijkstra(g,c1); // for(i=0;i
v[c1]; visit[c1]=1; memset(visit,0,sizeof(visit)); dfs(g,c1); printf("%d %d\n",count,maxper); return 0;}

 

 

 

转载于:https://www.cnblogs.com/scjyldq/archive/2012/10/03/2710724.html

你可能感兴趣的文章
springmvc整合mybatis框架源码 bootstrap html5
查看>>
Linux基础服务之FTP
查看>>
『中级篇』Dockerfile实战(19)
查看>>
lnmp安装---源码安装mysql5.6 -- nginx -- php -- memached
查看>>
实时同步inotify+rsync的简单部署
查看>>
MogileFS
查看>>
两个java客户端程序
查看>>
数据结构和算法分析之线性表
查看>>
理解volatile
查看>>
zabbix管理与使用
查看>>
linux服务器上安装Mysql数据库
查看>>
mysql kernel: nf_conntrack version 0.5.0
查看>>
每天都在记录新事物
查看>>
Python环境安装
查看>>
墙壁网线插座风波
查看>>
我的友情链接
查看>>
iOS内存暴增问题追查与使用陷阱
查看>>
MySQL 数据库上线后根据 status 状态优化
查看>>
win10重建图标缓存bat
查看>>
我的友情链接
查看>>