Max Stream Augmentation Path (km algorithm) hdoj 1533 going Home

Source: Internet
Author: User

Topic Portal

1 /*2 minimum cost flow: km algorithm is to find the maximum flow, as long as W =-W can be, very classical method3 */4#include <cstdio>5#include <cmath>6#include <algorithm>7#include <cstring>8 using namespacestd;9 Ten Const intMAXN = 1e2 +Ten; One Const intINF =0x3f3f3f3f; A intX[MAXN], Y[MAXN]; - intW[MAXN][MAXN]; - intVISX[MAXN], VISY[MAXN]; the intLY[MAXN]; - intMX[MAXN], MY[MAXN]; - intHX[MAXN], HY[MAXN]; - CharMAZE[MAXN][MAXN]; + intN, M, UN, vn, D; -  + BOOLDFS (intu) { AVisx[u] =true; at      for(intI=1; i<=un; ++i) { -         if(!visy[i] && X[u] + y[i] = =W[u][i]) { -Visy[i] =true; -             if(Ly[i] = =-1||DFS (Ly[i])) { -Ly[i] = u;return true; -             } in         } -         Else if(X[u] + y[i] > w[u][i]) d = min (d, x[u] + y[i]-w[u][i]); to     } +     return false; - } the  * intKM (void)    { $      for(intI=1; i<=un; ++i) {Panax NotoginsengX[i] =-INF; -          for(intj=1; j<=vn; ++j) { theX[i] =Max (X[i], w[i][j]);  +         } A     } the  +memset (Ly,-1,sizeof(ly)); -memset (Y,0,sizeof(y)); $      for(intI=1; i<=un; ++i) { $          while(true)    { -memset (VISX,false,sizeof(VISX)); -memset (Visy,false,sizeof(Visy)); theD =INF; -             if(DFS (i)) Break;Wuyi              for(intI=1; i<=un; ++i) { the                 if(Visx[i]) x[i]-=D; -             } Wu              for(intj=1; j<=vn; ++j) { -                 if(Visy[j]) y[j] + =D; About             } $         } -     } -  -     intres =0; A      for(intI=1; i<=un; ++i) { +Res + = X[i] +Y[i]; the     } -  $     returnRes; the } the  the intMainvoid)  {//hdoj 1533 going Home the     //freopen ("hdoj_1533.in", "R", stdin); -  in      while(SCANF ("%d%d", &n, &m) = =2) { the         if(!n &&!m) Break; the          for(intI=1; i<=n; ++i) { Aboutscanf ("%s", Maze[i] +1); the         } theUn = VN =0; the          for(intI=1; i<=n; ++i) { +              for(intj=1; j<=m; ++j) { -                 if(Maze[i][j] = ='m') Mx[++un] = i, my[un] =J; the                 Else if(Maze[i][j] = ='H') HX[++VN] = i, hy[vn] =J;Bayi             } the         } the          for(intI=1; i<=un; ++i) { -              for(intj=1; j<=vn; ++j) { -W[I][J] =-(ABS (Mx[i]-hx[j]) + ABS (my[i)-hy[j])); the             } the         } theprintf ("%d\n", -KM ()); the     } -  the     return 0; the}

Max Stream Augmentation Path (km algorithm) hdoj 1533 going Home

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.