# HDU 1874 smooth engineering continued

Source: Internet
Author: User

Idea: a type of deformation of the Dijkstra algorithm directly applies the template. For more information, see my other article! It should be noted that when there is a duplicate edge in this question, in the actual application (if it is the same good way), of course, it is the path with the smallest choice =

AC code:

`# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; # define INF 0x3f3f3f3int map [212] [212], DIS [212], visited [212]; int n, m; void Dijkstra (int x) {int I, P, J, min; for (I = 0; I <n; I ++) {dis [I] = map [x] [I]; visited [I] = 0;} dis [x] = 0; visited [x] = 1; for (I = 0; I <n; I ++) {min = inf; For (j = 0; j <n; j ++) {If (! Visited [J] & dis [J] <min) {P = J; min = dis [J] ;}} visited [p] = 1; for (j = 0; j <n; j ++) {If (! Visited [J] & dis [p] + map [p] [J] <dis [J]) {dis [J] = dis [p] + map [p] [J] ;}}} int main () {int I, j, a, B, T, s, E; while (scanf ("% d", & N, & M )! = EOF) {for (I = 0; I <n; I ++) for (j = 0; j <n; j ++) {map [I] [J] = inf ;}for (I = 1; I <= m; I ++) {scanf ("% d ", & A, & B, & T); If (T <map [a] [B]) map [a] [B] = map [B] [a] = T;} scanf ("% d", & S, & E); Dijkstra (s ); if (DIS [e] = inf) printf ("-1 \ n"); else printf ("% d \ n", DIS [e]);} return 0 ;}`

Related Keywords:

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.