Poj 2263 heavy cargo (zoj 1952)

Source: Internet
Author: User

The shortest path or the maximum Spanning Tree deformation.


Ask about the small weight that can be passed between two locations.

Use the shortest path to assign the initial value to INF, And the other value to 0. Then find dis [v] = min (DIS [u], d );

The spanning tree is to find the maximum spanning tree until the start and end points can communicate with each other, and the smallest side is.


Kruskal:

# Include <cstdio> # include <cstring> # include <string> # include <queue> # include <algorithm> # include <map> # include <stack> # include <iostream> # include <list> # include <set> # include <cmath> # define INF 0x7fffffff # define EPS 1e-6 # define ll long longusing namespace STD; int n, m; int Fa [201]; Map <string, int> city; struct lx {int U, V, Len;} l [19901]; int father (int x) {If (X! = Fa [x]) return Fa [x] = Father (Fa [x]);} bool CMP (lx a, lx B) {return. len> B. len;} int main () {int nn = 1; while (scanf ("% d", & N, & M), N | m) {for (INT I = 0; I <= N; I ++) Fa [I] = I; city. clear (); char a [31], B [31]; int Len, U, V, COT = 0; For (INT I = 0; I <m; I ++) {scanf ("% S % d", a, B, & Len); U = City [a]; If (u = 0) city [a] = cot ++; u = City [a]; V = City [B]; If (V = 0) City [B] = cot ++; V = City [B]; L [I]. U = u, L [I]. V = V, L [I]. len = Len;} scanf ("% S % s", a, B); int x = City [a]; int y = City [B]; sort (L, L + M, CMP); int ans = inf; For (INT I = 0; I <m; I ++) {u = Father (L [I]. u); V = Father (L [I]. v); If (u = V) continue; Fa [v] = u; ans = min (ANS, L [I]. len); If (father (x) = Father (y) break;} printf ("Scenario # % d \ n % d tons \ n ", nn ++, ANS );}}


Poj 2263 heavy cargo (zoj 1952)

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.