Minimum bottleneck spanning tree

Source: Internet
Author: User

The so-called minimal bottleneck spanning tree .... is to minimize the maximum edge weight on the spanning tree.

Here is the main introduction of a desired O (M) (linear) method, in fact, is mainly two points, the specific idea is as follows:

Analogy to find the method of K large value, first random one edge right w.

Then join the side that does not exceed this edge to traverse the graph.

If the diagram is connected, then the bottleneck does not exceed W, so just consider the edge of the edge not exceeding W.

Otherwise, the connecting points are shrunk and the edges of the edge greater than w are considered.

Reduce the size of the problem to half the time.

Expected time complexity O (m).

There are two related examples:

A.hangar Hurdles (CERC 16)

There is a grid of n*n, some squares are feasible, some lattices are obstacles. Q A query, want to push a square box from (R1,C1) to (R2,C2), ask the maximum size of the box. (The starting point is the midpoint of the square box) n<=1000 q<=300000

B. The clams have a pipe width of l , which we can view as a line of y=L and a portion of the X- axis.

(So the length of the pipe can be considered positive infinity)

There's one in this pipe.N obstacle point, < Span id= "mjxp-span-11" class= "Mjxp-math" >i obstacle point coordinates are ( Xi,Yi)

A sphere is known to be able to walk from the leftmost end of the pipe to the far right, without touching the barrier. (That is, from the pipe inside the negative infinity of the place to the horizontal axis of infinity).

What is the maximum diameter of this sphere? To avoid accuracy errors, output answers that retain three decimal places.

Two questions have the same wonderful ... (/funny, the idea is almost ...) ) can be minimized with minimal bottleneck tree

Here's The T2 code: (no optimization with minimum bottleneck tree, Escape)

1#include <bits/stdc++.h>2 #defineMAXN 5053 using namespacestd;4 structeage{5     intu,v;6     DoubleDist;7}e[maxn*maxn/2+maxn*2];8 BOOLCMP (eage a,eage b) {9     returna.dist<b.dist;Ten } One DoubleDisintX1,intY1,intX2,inty2) { A     returnsqrt1.0* (X1-X2) * (X1-X2) +1.0* (y1-y2) * (y1-y2));  - } - intFA[MAXN]; the intFindintx) { -     if(fa[x]==x)returnx; -     introot=find (Fa[x]); -fa[x]=Root; +     returnRoot; - } + voidLinkintXinty) { A     intFx=find (x), fy=find (y); at     if(fx!=FY) { -fa[fx]=fy; -     }  - } - BOOLCheckintXinty) { -     intFx=find (x), fy=find (y); in     if(FX!=FY)return false; -     return true; to } + intL,n; - structnode{ the     intx, y; * }ND[MAXN]; $ voidinit () {Panax Notoginseng     intpos=0; -scanf"%d%d",&n,&l); the      for(intI=1; i<=n+2; i++) fa[i]=i;//n+1 is on, n+2 is under +      for(intI=1; i<=n;i++){ Ascanf"%d%d",&nd[i].x,&nd[i].y); the     } +      for(intI=1; i<=n;i++){ -E[++pos]= (eage) {i,n+1, L-nd[i].y}; $E[++pos]= (eage) {i,n+2, nd[i].y}; $      for(intj=i+1; j<=n;j++){ -e[++pos]=(eage) {I,j,dis (ND[I].X,ND[I].Y,ND[J].X,ND[J].Y)}; -     } the     } -     intCnt=0;WuyiSort (e+1, e+pos+1, CMP); the      for(intI=1; i<=pos;i++){ -         intu=e[i].u,v=e[i].v; Wu         if(check (U,V))Continue; - link (u,v); Aboutcnt++; $         if(Find (n+1) ==find (n+2)){//as long as the bottom and bottom are connected, the maximum value can be guaranteed by -                                  //if the back is bigger, it's not going to be here. -printf"%.3f", e[i].dist); -              Break; A         } +     } the } - intMain () { $ init (); the      the     return 0; the}

Minimum bottleneck spanning tree

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.