zoukankan      html  css  js  c++  java
  • hdu 1532&&poj1273 基础最大流

    #include<stdio.h>
    #include<string.h>
    #include<queue>
    #include<iostream>
    using namespace std;
    #define N 300
    #define inf 2000000000
    int map[N][N];
    int start,end,flow[N],pre[N];
    int bfs() {
       int i,now;
      memset(pre,-1,sizeof(pre));
       flow[start]=inf;
       queue<int>q;
       while(!q.empty())
      q.pop();
       q.push(start);
       while(!q.empty()) {
       now=q.front();
       q.pop();
       for(i=1;i<=end;i++)
      if(i!=start&&pre[i]==-1&&map[now][i]) {
      flow[i]=flow[now]<map[now][i]?flow[now]:map[now][i];
      q.push(i);
      pre[i]=now;
      }
       }
       if(pre[end]==-1)return -1;
       return flow[end];
    }
    int ek(){
    int maxflow=0,now,step,pr;
    while((step=bfs())!=-1) {
       maxflow+=step;
       now=end;
       while(now!=start) {
      pr=pre[now];
      map[pr][now]-=step;
           map[now][pr]+=step;
      now=pr;
       }
    }
    return maxflow;
    }
    int main() {
    int n,m,a,b,c;
        while(scanf("%d%d",&n,&m)!=EOF) {
    memset(map,0,sizeof(map));
    start=1;end=m;
    while(n--) {
    scanf("%d%d%d",&a,&b,&c);
    map[a][b]+=c;
    }
    printf("%d ",ek());
    }
    return 0;
    }
  • 相关阅读:
    Vue 介绍
    Django 组件-分页器
    Django 组件content_type
    DRF 解析器组件
    Django
    Django 组件-ModelForm
    Django 组件-用户认证
    Django 组件-中间件
    Django 组件-cookie与session
    Django CBV与FBV
  • 原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410827.html
Copyright © 2011-2022 走看看