#include<stdio.h>#include<string.h>#include<algorithm>Usingnamespace Std;Constint maxv=510;Constint inf=0X3FFFFFFF;int n,m,c1,c2;BOOL VIS[MAXV];int G[MAXV][MAXV];Distance between citiesint WEIGHT[MAXV];Number of rescuers in each cityint D[MAXV];Shortest distanceint W[MAXV];Can bring the most peopleint NUM[MAXV];Shortest Path Bar numbervoid Dijkstra (int s) {memset (num,0,sizeof (num)); memset (Vis,Falsesizeof (VIS)); Fill (D,d+maxv,inf); Memset (W,0,sizeof (w)); d[s]=0;The city distance to the city is 0 W[s]=weight[s];The number of rescue teams in their own city num[s]=1;The shortest route to your city is 1Forint i=0; I<n; ++i) {int min=inf,u=-1;Forint j=0; J<n; ++J)Find Minimum D {if (vis[j]==False && Min>d[j]) {min=d[j]; u=j;}}if (-1==U)The graph has disconnected partsReturn vis[u]=TrueForint v=0; V<n; ++V) {if (vis[v]==False && G[u][v]!=inf) {if (D[v]>d[u]+g[u][v]) {D[V]=D[U]+G[U][V];Update shortest distance w[v]=w[u]+weight[v];Updated number of rescuers num[v]=num[u];"Warning" to the new shortest path, of course, is the number of U}Elseif (D[v]==d[u]+g[u][v]) {num[v]+=num[u];"Warning" number of bars with the shortest path number of U +vif (W[v]<w[u]+weight[v]) {W[V]=W[U]+WEIGHT[V];The same path, the maximum number of rescue teams}}}}}int main () {Fill (g[0],g[0]+maxv*maxv,inf); scanf"%d%d%d%d", &N,&M,&C1,&C2);Forint i=0; I<n; ++i)//deposit to each city Rescue team scanf ( "% Dfor (int i=0; i<m; ++i) //deposit between city distance {int u,v; scanf (" Span class= "content" >%d%d "&u,&v"; scanf ( "%d" &g[u ][V]); G[V][U]=G[U][V]; } Dijkstra (C1); printf ( "%d%d\nreturn 0;}
Pat:1003. Emergency (+) AC