Codevs 1557 heat wave

Source: Internet
Author: User

Texas's simple people are suffering a huge heat wave this summer!!! Their Texas horned cows are good to eat, but they are not very good at producing cream-rich dairy products. Farmer John at this time first, enjoy spirit, Shenxianshizu to Texas to carry a large number of nutritious cold milk, to alleviate the Texan people endure the pain of heat.

FJ has studied the route of transporting milk from Wisconsin to Texas. These routes include a starting point and an end point in a total of T (1 <= t <= 2,500) towns, conveniently labeled as 1 to T. In addition to the beginning and end of the field each town is connected by two bidirectional roads to at least two other towns. Each road has a pass fee (including fuel, toll, etc.).

Given a map that contains the C (1 <= C <= 6,200) strip directly connected to the road of 2 towns. Each road consists of the beginning of the road Rs, the end point Re (1 <= Rs <= t; 1 <= Re <= t), and the cost (1 <= Ci <=) . The minimum total cost for the town Te (1 <= te <= t) from the beginning of the town TS (1 <= TS <= t) to the end point .

This problem is used Dijkstra, AC also understand the meaning of the Dijkstra algorithm.

Variable function as its name, easy for beginners to learn together

1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4 #defineMAX 10000005 intmap[2501][2501];//the previous dimension represents the starting point, and the latter one represents the terminating point6 intpointspassed[2501],shortestdist[2501];7 intT,c,ts,te;//t= Town number c= Road number ts= start town te= End Town8 intRs,re,ci;9 Ten intMain () One { A     intI,j,nowmindist,topoint; -scanf"%d%d%d%d",&t,&c,&ts,&Te); -      the      for(i=1; i<=t;i++) -          for(j=1; j<=t;j++) -map[i][j]=MAX; -              +      for(i=1; i<=c;i++)  -     { +scanf"%d%d%d",&rs,&re,&Ci); A         if(Ci<=map[rs][re])//depending on the input there may be a cheaper way at         { -map[rs][re]=Ci; -map[re][rs]=Ci; -         } -     } -map[ts][ts]=0; in      -      for(i=1; i<=t;i++)//Initialize to     { +shortestdist[i]=Map[ts][i];  -pointspassed[i]=0; the     } *pointspassed[ts]=1; $     Panax Notoginseng      for(i=2; i<=t;i++) -     { thenowmindist=MAX; +Topoint=ts;//each time from the starting point to find the shortest distance from the A                    //now it's just the shortest path known to this point . the                        +          for(j=1; j<=t;j++) -             if((!pointspassed[j]) && shortestdist[j]<nowmindist) $             { $Topoint=J; -nowmindist=Shortestdist[j]; -             } the          -         //ingest this pointWuyipointspassed[topoint]=1; the          for(j=1; j<=t;j++) -             if((!pointspassed[j]) && Map[topoint][j]!=max)//extend the outward point from this point Wu                  if(Shortestdist[topoint] + map[topoint][j] <Shortestdist[j]) -Shortestdist[j]=shortestdist[topoint] +Map[topoint][j]; About     }  $      -printf"%d", Shortestdist[te]); -     return 0; -}

Codevs 1557 heat wave

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.