POJ 2584 T-shirt Gumbo Network stream

Source: Internet
Author: User

Topic links

There are 5 kinds of T-shirt, n individuals, each of whom can accept certain kinds of T-shirt, the number of each T-shirt is known, ask everyone to wear their own acceptable T-shirt.

The source points are connected to each type of T-shirt, and the weights are the number of values. The person is split into two points u and U ', the T-shirt to u edge, the weight value is 1, u to u ' Edge, the weight value is 1, U ' to the meeting point edge, the value is INF. Run the maximum flow, and see if the result equals N.

Very simple inscribed for a long time orz .... The code is too poor.

1#include <bits/stdc++.h>2 using namespacestd;3 #defineMem (a) memset (a, 0, sizeof (a))4 #defineMem1 (a) memset (a,-1, sizeof (a))5 Const intINF =1061109567;6 Const intMAXN = 1e4+5;7 inthead[maxn*4], S, T, NUM, q[maxn*Ten], DIS[MAXN];8 structnode9 {Ten     intto, Nextt, C; One}e[maxn*4]; A voidinit () { - mem1 (head); -num =0; the } - voidAddintUintVintc) { -E[num].to = v; E[num].nextt = Head[u]; E[NUM].C = C; Head[u] = num++; -e[num].to = u; E[num].nextt = Head[v]; E[NUM].C =0; HEAD[V] = num++; + } - intBFs () { +     intU, V, st =0, ed =0; A mem (dis); atDis[s] =1; -q[ed++] =s; -      while(st<ed) { -U = q[st++]; -          for(inti = Head[u]; ~i; i =e[i].nextt) { -v =e[i].to; in             if(e[i].c&&!Dis[v]) { -DIS[V] = dis[u]+1; to                 if(v = =t) +                     return 1; -q[ed++] =v; the             } *         } $     }Panax Notoginseng     return 0; - } the intDfsintUintlimit) { +     if(U = =t) A         returnlimit; the     intCost =0; +      for(inti = Head[u]; ~i; i =e[i].nextt) { -         intv =e[i].to; $         if(E[i].c&&dis[u] = = dis[v]-1) { $             intTMP = DFS (V, min (limit-Cost , e[i].c)); -             if(tmp>0) { -E[I].C-=tmp; thee[i^1].C + =tmp; -Cost + =tmp;Wuyi                 if(Cost = =limit) the                      Break; -}Else { WuDIS[V] =-1; -             } About         } $     } -     returnCost ; - } - intDinic () { A     intAns =0; +      while(BFS ()) { theAns + =DFS (s, INF); -     } $     returnans; the } theMap <Char,int>m; the intval[6]; the Charc[ -][3]; - intMain () in { them['S'] =1, m['M'] =2, m['L'] =3, m['X'] =4, m['T'] =5; the     stringstr; About     intN; the      while(cin>>str) { the init (); the         if(str = ="Endofinput") +              Break; -scanf"%d", &n); thes =0, t =2*n+5+1;Bayi          for(inti =1; i<=n; i++) { thescanf"%s", C[i]); the         } -          for(inti =1; i<=5; i++) { -scanf"%d", &val[i]); the         } the          for(inti =1; i<=5; i++) { the Add (S, I, Val[i]); the         } -          for(inti =1; i<=n; i++) { the             if(c[i][0] = = c[i][1]) { theAdd (m[c[i][0]], i+5,1); the}Else {94                  for(intj = m[c[i][0]]; j<=m[c[i][1]]; J + +) { theAdd (J, i+5,1); the                 } the             }98         } About          for(inti =1; i<=n; i++) { -Add (i+5, i+5+n,1);101Add (i+5+N, T, INF);102         }103Cin>>str;104         intAns =dinic (); the         if(ans = =N) {106cout<<"T-shirts rock!"<<Endl;107}Else {108cout<<"I ' d rather not wear a shirt anyway ..."<<Endl;109         } the     }111}

POJ 2584 T-shirt Gumbo Network 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.