Max Stream Augmentation Path (km algorithm) HDOJ 1853 Cyclic Tour

Source: Internet
Author: User

Topic Portal

1 /*2 KM: Compared to hdoj_1533, more heavy-edge processing, and a perfect match to determine the 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]; - intN, M, D; -  - BOOLDFS (intu) { +Visx[u] =true; -      for(intI=1; i<=n; ++i) { +         if(!visy[i] && X[u] + y[i] = =W[u][i]) { AVisy[i] =true; at             if(Ly[i] = =-1||DFS (Ly[i])) { -Ly[i] = u;return true; -             } -         } -         Else if(X[u] + y[i] > w[u][i]) d = min (d, x[u] + y[i]-w[u][i]); -     } in     return false; - } to  + intKM (void)    { -      for(intI=1; i<=n; ++i) { theX[i] =-INF; *          for(intj=1; j<=n; ++j) { $X[i] =Max (X[i], w[i][j]); Panax Notoginseng         } -     } the  +memset (Ly,-1,sizeof(ly)); Amemset (Y,0,sizeof(y)); the      for(intI=1; i<=n; ++i) { +          while(true)    { -memset (VISX,false,sizeof(VISX)); $memset (Visy,false,sizeof(Visy)); $D =INF; -             if(DFS (i)) Break; -              for(intI=1; i<=n; ++i) { the                 if(Visx[i]) x[i]-=D; -             }Wuyi              for(intj=1; j<=n; ++j) { the                 if(Visy[j]) y[j] + =D; -             } Wu         } -     } About  $      for(intI=1; i<=n; ++i) { -         if(Ly[i] = =-1|| W[ly[i]][i] = =-inf)return-1; -     } -  A     intres =0; +      for(intI=1; i<=n; ++i) { theRes + = X[i] +Y[i]; -     } $  the     return-Res; the } the  the intMainvoid)  {//hdoj 1853 Cyclic Tour -     //freopen ("hdoj_1853.in", "R", stdin); in  the      while(SCANF ("%d%d", &n, &m) = =2) { the         if(!n &&!m) Break; About          for(intI=1; i<=n; ++i) { the              for(intj=1; j<=n; ++J) W[i][j] =-INF; the         } the          for(intI=1; i<=m; ++i) { +             intU, V, c; scanf ("%d%d%d", &u, &v, &c); -             if(-c > W[u][v]) w[u][v] =-C; the         }Bayiprintf ("%d\n", KM ()); the     } the  -     return 0; -}

Max Stream Augmentation Path (km algorithm) HDOJ 1853 Cyclic Tour

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.