HDU 2544 (bare question]

Source: Internet
Author: User
Link: http://acm.hdu.edu.cn/showproblem.php? PID = 2544 http://acm.hust.edu.cn/vjudge/contest/view.action? Cid = 29015 # Problem/A Short Circuit

Time Limit: 5000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 22670 accepted submission (s): 9663


Problem description in each year's competition, all the finalists will get a very beautiful T-shirt. However, every time our staff moved hundreds of pieces of clothing from the store back to the stadium, they were very tired! So now they want to find the shortest route from the store to the stadium. Can you help them?


The input includes multiple groups of data. The first row of each group of data is two integers, N and M (n <= 100, m <= 10000). N indicates several intersections on the streets of Chengdu, the intersection marked as 1 is the location of the store, the intersection marked as n is the location of the stadium, and m represents several roads in Chengdu. N = m = 0 indicates that the input is complete. In the next m row, each row contains three integers, A, B, and C (1 <= A, B <= N, 1 <= C <= 1000 ), it means there is a road between Intersection a and intersection B. Our staff need to walk this road in C minutes.
Enter a route to ensure there is at least one store.


Output outputs a line for each input group, indicating the shortest time for a staff member to walk from the store to the stadium.


Sample Input

 
2 11 2 33 31 2 52 3 53 1 20 0


Sample output

 
32


Sourceuestc 6th Programming Contest online


Recommendlcy

Code:

# Include <stdio. h> # include <string. h ># include <algorithm> using namespace STD; const int maxn = 110; const int INF = 110*10000; int W [maxn] [maxn]; int d [maxn]; int vis [maxn]; int n, m; void Dijkstra () {for (INT I = 1; I <= N; I ++) d [I] = W [1] [I]; d [1] = 0; memset (VIS, 0, sizeof (VIS); For (INT I = 1; I <= N; I ++) {int M = inf; int X; For (INT y = 1; y <= N; y ++) if (! Vis [y] & D [y] <= m) M = d [x = y]; vis [x] = 1; for (INT y = 1; Y <= N; y ++) d [y] = min (d [Y], d [x] + W [x] [Y]);} int main () {While (scanf ("% d", & N, & M )! = EOF) {If (n = 0 & M = 0) break; For (INT I = 1; I <= N; I ++) {for (Int J = 1; j <= N; j ++) W [I] [J] = (I = J? 0: INF) ;}int a, B, weight; For (INT I = 0; I <m; I ++) {scanf ("% d ", & A, & B, & weight); W [a] [B] = min (W [a] [B], weight ); W [B] [a] = W [a] [B];} Dijkstra (); printf ("% d \ n", d [N]);} return 0 ;}

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.