pat:1003. Emergency (+) AC

Source: Internet
Author: User

#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", &AMP;N,&AMP;M,&AMP;C1,&AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.