zoukankan      html  css  js  c++  java
  • hdu 1273最大流

    #include<stdio.h>
    #include<string.h>
    #define inf 1000000000
    #include<queue>
    #define N  300
    using namespace std;
    int map[N][N],n,pre[N];
    int min(int a,int b) {
    return a>b?b:a;
    }
    int spfa(){
      int  now,cur,maxf[N];
      queue<int>q;
      int i;
      memset(pre,-1,sizeof(pre));
      for(i=1;i<=n;i++)
      maxf[i]=inf;
      q.push(1);
      pre[1]=0;
      while(!q.empty()) {
      cur=q.front();
      q.pop();
      for(now=1;now<=n;now++) {
     if(map[cur][now]&&pre[now]==-1) {
     pre[now]=cur;
     maxf[now]=min(maxf[cur],map[cur][now]);
     q.push(now);
     }
      }
      }
      if(pre[n]==-1)return 0;
      return  maxf[n];
    }
    int ek(){
    int kejia,h,now,maxflow=0;
    while(kejia=spfa()) {
          maxflow+=kejia;
     now=n;
     while(now!=0) {
     h=pre[now];
     map[h][now]-=kejia;
     map[now][h]+=kejia;
     now=h;
     }
    }
    return maxflow;
    }
    int main() {
    int m,a,b,c,i;
    while(scanf("%d%d",&m,&n)!=EOF) {
    memset(map,0,sizeof(map));
    for(i=1;i<=m;i++) {
    scanf("%d%d%d",&a,&b,&c);
    map[a][b]+=c;
    }
    printf("%d ",ek());
    }
    return 0;
    }
  • 相关阅读:
    老杳:2017年中国集成电路产业十大新闻
    RMA退货流程解决方案
    Linux
    vue.js
    NET Core度身定制的AOP框架
    Timeline
    HTTP
    MVC 常用扩展点:过滤器、模型绑定等
    装箱拆箱
    jQuery Tree
  • 原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410816.html
Copyright © 2011-2022 走看看