Bzoj 2561 minimum spanning tree "max Stream"

Source: Internet
Author: User

Description

Given a connected undirected graph g= (v,e) with a positive edge, where n=| v|,m=| E|,n points are numbered from 1 to N, given three positive integers u,v, and L (U≠V), assuming that you now add an edge (u,v) to the edge of L, then you need to delete the minimum number of edges to be able to make the edge appear either on the smallest spanning tree or on the largest spanning tree?

Solution

Test instructions: In one diagram, ask if one edge is on the smallest spanning tree and how many edges need to be deleted from the graph on the maximum spanning tree

What are the necessary and sufficient conditions for an edge not to be selected on the minimum spanning tree?

This edge cannot be selected when the smaller side has connected the two points to which it is connected.

The largest spanning tree is also

So, consider the minimum spanning tree first.

If this edge is not in the smallest spanning tree, edges that are smaller than it must be connected to the node you and V on this edge

We want to spend as little as possible to make u,v no longer connected.

Obviously the problem is converted to the smallest cut

Do one time for the smallest spanning tree and then the maximum spanning tree once, and the answer will add up.

1#include <bits/stdc++.h>2 3 #defineMAXN 20000+54 #defineMAXM 600000+55 #defineSet (a B) memset (A, (b), sizeof (a))6 #defineFR (i,a,b) for (ll i= (a), _end_= (b); i<=_end_;i++)7 #defineRF (I,b,a) for (ll i= (a), _end_= (b); i>=_end_;i--)8 #defineFe (I,A,B) for (int i=first[(b)],_end_= (a); i!=_end_;i=s[i].next)9 #defineFEC (I,A,B) for (int &i=cur[(b)],_end_= (a); i!=_end_;i=s[i].next)Ten  One using namespacestd; A  -typedefLong Longll; -  the structsides{ -   intu,v,c; -   intNext; - }S[MAXM]; +  - structedge{ +   intu,v,w; AFriendBOOL operator<(Edge A,edge b) { at     returna.w<B.W; -   } - }E[MAXM]; -  -queue<int>Q; - intH[MAXN],FIRST[MAXN],CUR[MAXN]; in intInd=0; - intcost=0; to intn,m,sp,tp,p; +  - BOOLComp (Edge A,edge B) the { *   returna.w<B.W; $ }Panax Notoginseng  - voidAddintUintVintc) the { +S[ind].u=u,s[ind].v=v,s[ind].c=C; As[ind].next=first[u],first[u]=IND; theind++; +    -S[ind].u=v,s[ind].v=u,s[ind].c=C; $s[ind].next=first[v],first[v]=IND; $ind++; - } -  the BOOLBFS () - {Wuyi   Set(h,-1); theh[sp]=0; - Q.push (SP); Wu    while( !Q.empty ()) { -     intSd=Q.front (); Q.pop (); AboutFe (i,-1, SD) $       if(h[s[i].v]==-1&&s[i].c) { -h[s[i].v]=h[sd]+1; - Q.push (S[I].V); -       } A   } +   returnh[tp]!=-1; the } -  $ intDfsintSdintflow) the { the   if(SD==TP)returnflow; the   intW,used=0; theFEC (i,-1, SD) -     if(h[s[i].v]==h[sd]+1&&s[i].c) { inW=dfs (S[i].v,min (flow-used,s[i].c)); thes[i].c-=w,s[i^1].c+=W; theused+=W; About       if(Used==flow)returnflow; the     } the   if(!used) h[sd]=1; the   returnused; + } -  the voiddinic ()Bayi { the    while(BFS ()) { theFr (I,0, n+1) -cur[i]=First[i]; -cost+=DFS (Sp,int_max); the   } the } the  the voidSolve () - { theInd=0; the   Set(first,-1); theFr (I,1, M)94     if(e[i].w<p) theAdd (E[I].U,E[I].V,1); the     Else  Break; the dinic ();98    AboutInd=0; -   Set(first,-1);101RF (I,1, M)102     if(e[i].w>p)103Add (E[I].U,E[I].V,1);104     Else  Break; the dinic ();106 }107 108 intMain ()109 { the #ifndef Online_judge111Freopen ("2561.in","R", stdin); theFreopen ("2561.out","W", stdout);113 #endif theCIN >> N >>m; theFr (I,1, M) theCIN >> e[i].u >> e[i].v >>E[I].W;117Sort (e+1, e+m+1, comp);118CIN >> SP >> TP >>p;119 solve (); -cout <<Cost ;121   return 0;122}

Bzoj 2561 minimum spanning tree "max Stream"

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.