Zoj 3792 Romantic Value

Source: Internet
Author: User

Topic links

The minimum cut value, and the number of edges with the least cutting edge.

First, the minimum cut, and then the weight of all the cutting edge into 1, the other side into the INF, in the minimum cut, at this time to find the minimum number of sides.

INF to the INF WA a few rounds ......

1#include <bits/stdc++.h>2 using namespacestd;3 #definePB (x) push_back (x)4 #definell Long Long5 #defineMK (x, y) make_pair (x, y)6 #defineLson L, M, rt<<17 #defineMem (a) memset (a, 0, sizeof (a))8 #defineRson m+1, R, rt<<1|19 #defineMem1 (a) memset (a,-1, sizeof (a))Ten #defineMEM2 (a) memset (a, 0x3f, sizeof (a)) One #defineRep (I, A, n) for (int i = A; i<n; i++) A #defineull unsigned long Long -typedef pair<int,int>PLL; - Const DoublePI = ACOs (-1.0); the Const DoubleEPS = 1e-8; - Const intMoD = 1e9+7; - Const intINF =1e4; - Const intdir[][2] = { {-1,0}, {1,0}, {0, -1}, {0,1} }; + Const intMAXN = 2e5+5; - intNum, q[maxn*5], head[maxn*2], dis[maxn*2], S, t; + structnode A { at     intto, Nextt, C; - node () {} -NodeintTo,intNextt,intc): To, Nextt (NEXTT), C (c) {} -}e[maxn*2]; - intBFs () { - mem (dis); in     intSt =0, ed =0; -Dis[s] =1; toq[ed++] =s; +      while(st<ed) { -         intU = q[st++]; the          for(inti = Head[u]; ~i; i =e[i].nextt) { *             intv =e[i].to; $             if(!dis[v]&&e[i].c) {Panax NotoginsengDIS[V] = dis[u]+1; -                 if(v = =t) the                     return 1; +q[ed++] =v; A             } the         } +     } -     return 0; $ } $ intDfsintUintlimit) { -     intCost =0; -     if(U = =t) the         returnlimit; -      for(inti = Head[u]; ~i; i =e[i].nextt) {Wuyi         intv =e[i].to; the         if(E[i].c&&dis[v] = = dis[u]+1) { -             intTMP = DFS (V, min (e[i].c, limit-Cost )); Wu             if(tmp>0) { -E[I].C-=tmp; Aboute[i^1].C + =tmp; $Cost + =tmp; -                 if(Cost = =limit) -                      Break; -}Else { ADIS[V] =-1; +             } the         } -     } $     returnCost ; the } the intDinic () { the     intAns =0; the      while(BFS ()) { -Ans + =DFS (s, INF); in     } the     returnans; the } About voidAddintUintVintc) { theE[num] = node (V, Head[u], c); Head[u] = num++; theE[num] = node (u, head[v], c); HEAD[V] = num++; the } + voidinit () { - mem1 (head); thenum =0;Bayi } the intMain () the { -     intT, M, n, x, y, q, p, Z; -Cin>>T; the      while(t--) { the init (); the         intsum =0; thescanf"%d%d%d%d", &n, &m, &p, &q); -s = p, t =Q; the          while(m--) { thescanf"%d%d%d", &x, &y, &z); the Add (x, y, z);94Sum + =Z; the         } the         intAns =dinic (); the         if(ans = =0) {98cout<<"INF"<<Endl; About             Continue; -         }101Sum-=ans;102          for(inti =0; i<num; i+=2) {103             if(E[I].C = =0) {104E[I].C =1; thee[i^1].C =inf;106}Else if(e[i^1].c==0) {107E[I].C =inf;108e[i^1].C =1;109}Else { theE[I].C = e[i^1].C =inf;111             } the         }113Ans =dinic (); theprintf"%.2f\n",1.0*sum/ans); the     } the}

Zoj 3792 Romantic Value

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.