Poj 1734. sightseeing trip solution report

Source: Internet
Author: User

Floyd minimum ring Template

Code

/* Floyd minimum ring, record path, time complexity O (N ^ 3) cannot process negative ring */# include <iostream> # include <cstring> using namespace STD; const int INF = 109, maxn = 252645135; int G [INF] [INF], DIS [INF] [INF], pre [INF] [INF]; int ans [INF]; // PR [I] [J] records the first vertex int n, m, TEM, Tol; int main () in the I-to-J Shortest Path () {While (CIN> N> m) {TEM = maxn; memset (G, 0xf, sizeof g); memset (DIS, 0xf, sizeof dis); memset (PRE, 0, sizeof pre); int x, y, z; For (INT I = 1; I <= m; I ++) {CIN> x> Y> Z; If (z <G [x] [Y]) dis [x] [Y] = dis [y] [x] = G [x] [Y] = G [y] [x] = z; pre [x] [Y] = Y, pre [y] [x] = x ;}for (int K = 1; k <= N; k ++) {for (INT I = 1; I <K; I ++) for (Int J = I + 1; j <K; j ++) {If (TEM> dis [I] [J] + G [I] [k] + G [k] [J]) {TEM = dis [I] [J] + G [I] [k] + G [k] [J]; int T = I; Tol = 0; while (T! = 0) {ans [++ tol] = T; t = pre [T] [J];} ans [++ tol] = K ;}} for (INT I = 1; I <= N; I ++) for (Int J = 1; j <= N; j ++) if (I! = J & dis [I] [k] + dis [k] [J] <dis [I] [J]) {dis [I] [J] = dis [I] [k] + dis [k] [J]; pre [I] [J] = pre [I] [k] ;}} if (TEM = maxn) cout <"no solution. "; elsefor (INT I = 1; I <= tol; I ++) cout <ans [I] <''; cout <Endl;} return 0 ;}

Poj 1734. sightseeing trip solution report

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.