"Bzoj" "3669" "NOI2014" magical Forest

Source: Internet
Author: User

LCT Dynamic Maintenance MST

LCT Dynamic Maintenance MST

We can enumerate a, and then find a path from 1 to n so that: the maximum value of B on this path is minimal. This path must be on MST ... So enumerate through all the edges and dynamically maintain an MST about the B value.

The reason why the tune has not been solved for half a day:

Rotate wrote the wrong ... l=c[y][1]==x I write l=c[z][1]==y sigh .....

1 /**************************************************************2 problem:36693 User:tunix4 language:c++5 result:accepted6 time:4752 Ms7 memory:7896 KB8 ****************************************************************/9  Ten //Bzoj 3669 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - using namespacestd; + intGetint () { A     intv=0, sign=1;CharCh=GetChar (); at      while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*=Sign ; - } - Const intn=150010, inf=~0u>>2; - /******************tamplate*********************/ in structlct{ -     intc[n][2],fa[n],v[n],mx[n]; to     BOOLRev[n]; +     intSt[n],top; - #defineL C[x][0] the #defineR C[x][1] *     voidPUSH_UP (intx) { $mx[x]=x;Panax Notoginseng         if(V[mx[l]]>v[mx[x]]) mx[x]=Mx[l]; -         if(V[mx[r]]>v[mx[x]]) mx[x]=Mx[r]; the     } +     voidPush_down (intx) { A         if(Rev[x]) rev[x]=0, rev[l]^=1, rev[r]^=1, swap (l,r); the     } +     BOOLNot_root (intx) { -         returnc[fa[x]][0]==x | | c[fa[x]][1]==x; $     } $     voidRotateintx) { -         inty=fa[x],z=fa[y],l=c[y][1]==x,r=l^1; -         if(Not_root (y)) c[z][c[z][1]==y]=x; theFa[x]=z; Fa[y]=x; fa[c[x][r]]=y; -C[Y][L]=C[X][R]; c[x][r]=y;Wuyi push_up (y); the     } -     voidPreviewintx) { Wutop=0; st[++top]=x; -          for(; Not_root (x); x=Fa[x]) Aboutst[++top]=Fa[x]; $D (I,top,1) Push_down (St[i]); -     } -     voidSplay (intXinty=0){ -          for(preview (x); not_root (x); rotate (x)) A             if(Not_root (y=fa[x])) +Rotate (c[y][1]==x^c[fa[y]][1]==y?x:y); the push_up (x); -     } $     voidAccessintXinty=0){ the          for(; X;splay (x), c[x][1]=y,y=x,x=fa[x]); the     } the     voidMakeroot (intx) { theAccess (x); Splay (x); rev[x]^=1; -     } in     voidLinkintXinty) { theMakeroot (x); fa[x]=y; the     } About     voidCutintXinty) { the makeroot (x); Access (y); splay (y) ; the         if(c[y][0]==X) c[y][0]=fa[x]=0; the     } +     intQueryintXinty) { - makeroot (x), Access (y), splay (y); the         returnMx[y];Bayi     } the }t; the /*********************lct***********************/ - structedge{ -     intx,y,a,b; the     BOOL operator< (ConstEdge &e)Const { the         returnA <E.a; the     } the }e[n]; - intFa[n]; the intFindintx) {returnFa[x]==x? x:fa[x]=find (Fa[x]);} the   the intMain () {94 #ifndef Online_judge theFreopen ("3669.in","R", stdin); theFreopen ("3669.out","W", stdout); the #endif98     intn,m; AboutN=getint (); m=getint (); -F (I,1, M) {101E[i].x=getint (); e[i].y=getint ();102E[i].a=getint (); e[i].b=getint ();103     }104Sort (e+1, e+m+1); theF (I,1, M) {106t.v[n+i]=e[i].b;107t.mx[n+i]=n+i;108     }109F (I,1, N) fa[i]=i; the      111     intans=INF; theF (I,1, M) {113         intF1=find (e[i].x), f2=find (E[I].Y); the         if(f1!=F2) { thefa[f1]=F2; theT.link (E[i].x,n+i); T.link (e[i].y,n+i);117         }118         Else{119             inttmp=t.query (E[I].X,E[I].Y); -             if(E[i].b<t.v[tmp]) {//This step can omit the self-loop121T.cut (E[TMP-N].X,TMP); T.cut (e[tmp-n].y,tmp);122T.link (E[i].x,i+n); T.link (e[i].y,i+n);123             }124         } theF1=find (1); F2=find (n);126         if(f1==F2)127Ans=min (Ans,e[i].a+t.v[t.query (1, N)]); -     }129printf"%d\n", Ans==inf? -1: ans); the     return 0;131}
View Code

"Bzoj" "3669" "NOI2014" magical Forest

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.