1003 Emergency (25 min)
As an emergency rescue team leader of a city, you is given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams and the length of each road between any pair of cities is marked on the map. When there is a emergency call to your from some and other city, your job are to leads your men to the place as quickly as Possi BLE, and at the mean time, call up as many hands on the same as possible.
Input Specification:
Each input file contains the one test case. For each test case, the first line contains 4 positive integers:N≤)-The number of cities (and the cities is numbered from 0 toN?1),M-the number of roads,C?1?? andC?2?? -The cities that is currently in and so you must save, respectively. The next line containsN integers, where thei-th Integer is the number of rescue teams in theI-th City. ThenM lines follow, each describes a road with three integersC?1??,C?2?? andL, which is the pair of cities connected by a road and the length of this road, respectively. It is guaranteed this there exists at least one path fromc< Span class= "Vlist" >?1?? to < Span class= "base textstyle uncramped" >c? 2? ?.
Output Specification:
For all test case, print in one line numbers:the number of different shortest paths betweenC? 1 ?? and < Span class= "base textstyle uncramped" >c? 2? ?, and the maximum amount of rescue teams you can possibly gather. All the numbers in a line must being separated by exactly one space, and there are 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
Sample Output:
This article I wrote according to other predecessors written by themselves, the submission of the reality only a correct, the rest of the error, I hope you help me find my mistake. Thanks for the thank you??
#include <stdio.h> #include <math.h> #include <stdbool.h> #define INF 9999999int main () {int N,M,C1,C2, I,j; int num[510],weight[510],dis[510],w[510];//num path strip number dis shortest path long W final troop number sum int e[510][510]; BOOL visit[510]; Tag Access scanf ("%d%d%d%d", &N,&M,&C1,&C2); for (i=0;i<n;i++) scanf ("%d", &weight[i]); The number of each vertex for (i=0;i<n;i++) {for (j=0;j<n;j++) {e[i][j]=inf; Resets the Matrix e vertex} dis[i]=inf; Reset Edge} int a,b,c; for (i=0;i<m;i++) {scanf ("%d%d%d", &a,&b,&c); E[a][b]=e[b][a]=c; Input side} dis[c1]=0; W[C1]=WEIGHT[C1]; Num[c1]=1; for (i=0;i<n;i++) {int u=-1,minn=inf; for (j=0;j<n;j++) {if (Visit[j]==false&&dis[j]<minn) {u=j;minn=dis[j]; }} if (U==-1) break; Visit[u]=true; for (int v=0;v<n;v++) {if (Visit[v]==false&&e[u][v]!=inf) {if (dis[v]+e[u][v]<dis[v]) {dis [V]=e[u][v]+dis[v]; Num[v]=nUm[u]; W[V]=W[U]+WEIGHT[V]; } else if (Dis[v]+e[u][v]==dis[v]) {NUM[V]=NUM[U]+NUM[V]; if (W[u]+weight[v]>w[v]) {W[V]=W[U]+WEIGHT[V]; }}}}} printf ("%d%d", num[c2],w[c2]); return 0;}
1003 Emergency (25 min) C language version (question solving answer)