zoukankan      html  css  js  c++  java
  • 模板题 codevs 1993 草地排水 想学习的请看链接

    不能再水的题了。

    Dinic算法,比EK更快。

    想要学习请看链接   https://comzyh.com/blog/archives/568/

    并附上我的模板(其实和comzyh大神的一样)

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<algorithm>
     4 using namespace std;
     5 int tab[203][203],dis[203],d[203],n,m;
     6 bool bfs()
     7 {
     8     int i,head=0,tail=0;
     9     memset(d,0,sizeof(d));
    10     memset(dis,0xff,sizeof(dis));
    11     d[0]=1; dis[1]=0;
    12     while (head<=tail)
    13     {
    14         for (i=1;i<=n;++i)
    15          if ((dis[i]<0)&&(tab[d[head]][i]>0))
    16          {
    17              dis[i]=dis[d[head]]+1;
    18              tail++; d[tail]=i;
    19          }
    20         head++;
    21     }
    22     if (dis[n]>0) return 1;
    23     else return 0;
    24 }
    25 int wll(int x,int low)
    26 {
    27     int i,a=0; if (x==n) return low;
    28     for (i=1;i<=n;++i)
    29      if ((tab[x][i]>0)&&(dis[i]==dis[x]+1)&&(a=wll(i,min(low,tab[x][i]))))
    30      {
    31          tab[x][i]-=a;
    32          tab[i][x]+=a;
    33          return a;
    34      }
    35      return 0;
    36 }
    37 int main()
    38 {
    39     scanf("%d %d
    ",&m,&n);
    40     int i,j,u,v,flow,ans=0,at;
    41     memset(tab,0,sizeof(tab));
    42     for (i=1;i<=m;++i)
    43     {
    44         scanf("%d %d %d
    ",&u,&v,&flow);
    45         tab[u][v]+=flow;
    46     }
    47     while (bfs())
    48     {
    49         while (at=wll(1,0x7fffffff)) ans+=at;
    50     }
    51     printf("%d
    ",ans);
    52 }
     
    NOI 2017 Bless All
  • 相关阅读:
    第八次作业
    微信用户体验
    •设计一款给爸爸妈妈用的手机
    对类的继承
    必应词典
    第二次作业二
    第二次作业
    我想搞的软工
    数字签名
    C++的学习心得
  • 原文地址:https://www.cnblogs.com/abclzr/p/5020525.html
Copyright © 2011-2022 走看看