题目链接

网络流入门@_@,此处本人用的刘汝佳的Dinic模板

#include<bits/stdc++.h>
using namespace std;

const int INF = 0x3f3f3f3f;

struct Edge
{
    int from,to,cap,flow;
};

int n,s,t,m;

struct Dinic
{
    , M = ;    //N对应点数

    vector<Edge> edges;
    vector<int> G[N];
    bool vis[N];
    int d[N];
    int cur[N];
    void init()
    {
        ; i<=n; i++)
            G[i].clear();
        edges.clear();
    }
    void AddEdge(int from,int to,int cap)
    {
        edges.push_back((Edge)
        {

        });
        edges.push_back((Edge)
        {
            to,,
        });
        int w=edges.size();
        G[);
        G[to].push_back(w-);
    }
    bool bfs()
    {
        memset(vis,,sizeof(vis));
        queue<int>Q;
        d[s] = ;
        Q.push(s);
        vis[s]=;
        while (!Q.empty())
        {
            int x = Q.front();
            Q.pop();
            ; i<G[x].size(); i++)
            {
                Edge e=edges[G[x][i]];
                if (!vis[e.to]&&e.cap>e.flow)
                {
                    vis[e.to]=;
                    d[e.to] = d[x] + ;
                    Q.push(e.to);
                }
            }
        }
        return vis[t];
    }
    int dfs(int x, int a)
    {
        ) return a;
        ,f;
        for (int&i = cur[x] ; i<G[x].size(); i++)
        {
            Edge& e=edges[G[x][i]];
            &&(f=dfs(e.to,min(a,e.cap-e.flow)))>)
            {
                e.flow+=f;
                edges[G[x][i]^].flow-=f;    //流量增大意味着净容量减少
                flow+=f;                    //反向边容量表示了正向边的流量
                a -= f;
                )break;
            }
        }
        return flow;
    }
    int Maxflow(int s, int t)
    {
        ;
        while (bfs())
        {
            memset(cur,,sizeof(cur));
            flow += dfs(s, INF);
        }
//        for(int i=1;i<=n;i++)
//            for(int j=0;j<G[i].size();j++)
//                printf("from:%d to:%d cap:%d flow:%d\n",i,edges[G[i][j]].to,edges[G[i][j]].cap,edges[G[i][j]].flow);
        return flow;
    }
} g;

int main()
{
    while(~scanf("%d%d",&m,&n))
    {
        g.init();
        s=;
        t=n;
        ; i<m; i++)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            g.AddEdge(a,b,c);
        }
        printf("%d\n",g.Maxflow(s,t));
    }
}

nyoj_323:Drainage Ditches(网络流入门)的更多相关文章

  1. POJ 1273 Drainage Ditches (网络流Dinic模板)

    Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...

  2. POJ 1273:Drainage Ditches 网络流模板题

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63339   Accepted: 2443 ...

  3. HDU1532 Drainage Ditches 网络流EK算法

    Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...

  4. USACO 4.2 Drainage Ditches(网络流模板题)

    Drainage DitchesHal Burch Every time it rains on Farmer John's fields, a pond forms over Bessie's fa ...

  5. NYOJ 323 Drainage Ditches 网络流 FF 练手

    Drainage Ditches 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 Every time it rains on Farmer John's fields, ...

  6. POJ 1273 Drainage Ditches 网络流 FF

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 74480   Accepted: 2895 ...

  7. Drainage Ditches~网络流模板

    Description Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover ...

  8. poj 1273 Drainage Ditches 网络流最大流基础

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 59176   Accepted: 2272 ...

  9. POJ-1273Drainage Ditches(网络流入门题,最大流)

    Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This ...

随机推荐

  1. JSON数据解析:Gson(谷歌)和fastjson(阿里巴巴)的异同点

    Gson和fastjson分别为谷歌和阿里巴巴对JSON数据进行处理封装的jar包 Gson(谷歌)和fastjson(阿里巴巴)两者异同点: 相同点:都是根据JSON数据创建相应的类 不同点: 1. ...

  2. DFS and BFS

    DFS https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master ...

  3. vscode中使用markdown

    vscode中使用markdown vscode 是微软推出一款轻量级的文本编辑工具,类似于sublime,由于其拥有丰富的插件,安装使用也非常简单,所以深受广大程序员的喜爱. markdown 是一 ...

  4. C#从基于FTPS的FTP server下载数据 (FtpWebRequest 的使用)SSL 加密

    FTPS,亦或是FTPES, 是FTP协议的一种扩展,用于对TLS和SSL协议的支持. 本文讲述了如何从一个基于FTPS的Server中下载数据的实例.   任何地方,如有纰漏,欢迎诸位道友指教.   ...

  5. 限制容器对CPU的使用 - 每天5分钟玩转 Docker 容器技术(28)

    上节学习了如何限制容器对内存的使用,本节我们来看CPU. 默认设置下,所有容器可以平等地使用 host CPU 资源并且没有限制. Docker 可以通过 -c 或 --cpu-shares 设置容器 ...

  6. ES6 常用总结——第一章(简介、let、const)

    ES6整理 1. ECMAScript 6简介 ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准.它的目标,是使得 JavaScript 语言可以用来编写复杂 ...

  7. Mac系统占用空间大、空间不够、查看系统文件大小分布

    最近电脑老提示空间不够,甚是心烦,决定研究下,为啥空间这么快就花完了. 如图,256的空间,就剩下几个G了,其中最大头的系统占用:160G,占比60%多,我勒个擦... 正常情况下:我们可以点击管理, ...

  8. linux系统中的删除操作

    #rm [-fir] 文件或者目录 参数: -f:就是force的意思,忽略不存在的文件,不会出现警告信息: -i:互动模式,在删除前会询问用户是否操作: -r:递归删除.最常用的在目录删除.这是一个 ...

  9. 利用Border画三角形

    边框 1.边框其实并不是矩形,而是梯形 2.利用边框画三角形: div.a{ width:0px; height:0px; border:10px white solid; border-top-co ...

  10. Python:一篇文章掌握Numpy的基本用法

    前言 Numpy是一个开源的Python科学计算库,它是python科学计算库的基础库,许多其他著名的科学计算库如Pandas,Scikit-learn等都要用到Numpy库的一些功能. 本文主要内容 ...