78,79行是精髓

61,148,149行是当前弧优化

 #include <cstring>
#include <cstdio>
#include <queue> #define Max 1000090
#define INF 1e9 void read (int &now)
{
now = ;
register char word = getchar ();
while (word < '' || word > '')
word = getchar ();
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
} int N, M, S, T; inline int min (int a, int b)
{
return a < b ? a : b;
} class Net_Flow_Type
{ private : int __to[Max * ];
int __next[Max * ]; int __flow[Max * ]; int Edge_Count;
int edge_list[Max]; int deep[Max], Answer; int Queue[Max * ];
int Head, Tail;
int __tech_[Max]; public : Net_Flow_Type ()
{
Edge_Count = ;
Answer = ;
} int Flowing (int now, int flow)
{
if (flow <= || now == T)
return flow;
int pos = , res; for (int &i = __tech_[now]; i; i = __next[i])
{
if (deep[__to[i]] != deep[now] + || __flow[i] <= )
continue;
res = Flowing (__to[i], std :: min (flow, __flow[i]));
if (res > )
{
flow -= res;
pos += res; __flow[i] -= res;
__flow[i ^ ] += res; if (flow <= )
return pos;
}
}
if (pos != flow)
deep[now] = -;
return pos;
} inline void Add_Edge (int from, int to, int flow)
{
Edge_Count ++;
__to[Edge_Count] = to; __next[Edge_Count] = edge_list[from];
edge_list[from] = Edge_Count; Edge_Count ++;
__to[Edge_Count] = from; __next[Edge_Count] = edge_list[to];
edge_list[to] = Edge_Count; __flow[Edge_Count - ] = flow;
__flow[Edge_Count] = ; } void Insert_edges ()
{
for (int i = , from, to, flow; i <= M; i ++)
{
read (from);
read (to);
read (flow); this->Add_Edge (from, to, flow);
}
} bool Bfs (int Start)
{ for (int i = ; i <= N; i ++)
deep[i] = -;
Head = , Tail = ;
Queue[Head] = Start; deep[Start] = ;
register int now; while (Head < Tail)
{
now = Queue[Head];
Head ++; for (int i = edge_list[now]; i; i = __next[i])
if (deep[__to[i]] == - && __flow[i])
{
deep[__to[i]] = deep[now] + ;
if (__to[i] == T)
return true; Queue[Tail ++] = __to[i];
}
} return deep[T] != -;
} int Dinic ()
{
while (Bfs (S))
{
for (int i = ; i <= N; i ++)
__tech_[i] = edge_list[i]; Answer += Flowing (S, INF);
} return Answer;
}
}; Net_Flow_Type Make; int main (int argc, char *argv[])
{
read (N);
read (M);
read (S);
read (T); Make.Insert_edges (); printf ("%d", Make.Dinic ()); return ;
}

永远不会被卡的Dinic的更多相关文章

  1. 科技界、IT届的外号

    牙膏厂 = Intel     挤牙膏来形容缓慢的升级速度 农企(推土机,打桩机,压路机).阿曼达.按摩店  = AMD 两弹元勋.老黄 = 黄仁勋,    核弹.英伟达 = NVIDIA 大法 = ...

  2. 【转载】Mini2440启动配置文件说明

    对于mini2440,虽然root_qtopia这个文件系统的GUI是基于Qtopia的,但其初始化启动过程却是由大部分由busybox完成,Qtopia(qpe)只是在启动的最后阶段被开启. 由于默 ...

  3. 洛谷 P1518 两只塔姆沃斯牛 The Tamworth Two

    P1518 两只塔姆沃斯牛 The Tamworth Two 题目背景 题目描述 两只牛逃跑到了森林里.农夫John开始用他的专家技术追捕这两头牛.你的任务是模拟他们的行为(牛和John). 追击在1 ...

  4. GJM :Unity使用EasyAR实现脱卡功能

    首先说下大致思路当卡片离开摄像头时间,ImageTarget-Image的SetActive (false),所以其子物体(model)也就不显示了,因此解决的办法就是在Target (false)时 ...

  5. 网络流dinic实现总结

    太羞耻了,搞了半天居然没发现自己写的不是dinic,直到被一道时限紧的题目卡掉才发现 int dfs(int now,int flow,int sum) { if(now==n) return flo ...

  6. HDU 3572 Task Schedule(拆点+最大流dinic)

    Task Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. PBOC规范下的java卡介绍

    JAVA卡与智能卡 什么是 JAVA 卡呢?JAVA 卡是一种可以运行 JAVA 程序的接触式微处理器智能卡.1996 年 11 月,JAVA 卡 1.0 版本的规范正式发布了.如今 JAVA 卡最新 ...

  8. STM32之SD卡

    目录 一.SD卡概述 1.定义 2.容量等级 3.SD卡框图 4.SD卡与TF卡的区别 二. SD卡内部结构 1. SD卡内部结构简图 2. 存储阵列结构图 3.Buffer 4.“存储阵列Block ...

  9. eclipse EE neon创建dynamic web project时,卡在installing dynamic web module facet,解决办法

    我们在用eclipse EE neon创建dynamic web project时,如果你发现底部状态栏一直卡在installing dynamic web module facet,永远到不了100 ...

随机推荐

  1. intellij idea 中右键项目没有git

    1.没有GIT选项说明还没有关联你的仓库 2.ctrl + alt +s 打开VersionControl添加git仓库 3.添加后再次查看,GIT就出现了 4.可以查看历史版本了. 原文地址:htt ...

  2. 全栈项目|小书架|服务器开发-NodeJS 项目分包

    唠嗑 参考的是慕课网七月老师的课程,七月的课质量真的挺高的,推荐一波.这次的小书架项目源码不会全部公开,因为用了七月老师课程的绝大部分代码.虽然代码不全,但是只要思路看得懂,代码实现就很简单了. 小书 ...

  3. IClientMessageInspector IDispatchMessageInspector

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. ElementUI对话框(dialog)提取为子组件

    需求:在页面的代码太多,想把弹窗代码提取为子组件,复用也方便.   这里涉及到弹窗el-dialog的一个属性show-close: show-close="false"是设置不显 ...

  5. UI5-技术篇-事务Tcode

    1.LPD_CUST 快速启动板概览 2./N/UI2/FLPD_CONF 创建目录与组(全部客户端) 3./N/UI2/FLPD_CUST 创建目录与组(当前客户端) 4./N/UI2/FLP 编辑 ...

  6. C#-FileHelper

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. 华为SDN:解决传统网络3大问题

    转:http://mp.ofweek.com/tele/a145613326756 科技潮人 2013-08-05 14:20 传统网络之困 互联网爆炸式增长,除了规模和发展速度远超之前所有曾出现的数 ...

  8. 静态链接 VS 动态链接

    什么是链接? 链接其实就是连接的意思,将所有相关的东西连接起来. 简单理解静态连接和动态链接: 静态链接:编译时完成链接 动态链接:程序运行起来后,根据需求再去链接,这就是动态链接 静态链接 什么是静 ...

  9. 如何写好demo——学习感悟

    文章标题:教你如何写好Demo应用 如何制作出最有用的demo呢? 简,易 在demo中,我们要专注于单一的主题.我们的教学覆盖了很大的知识范围,因此,化整为零是非常必要的. 例如,我们要说明Andr ...

  10. springboot 配置 中查找application.properties中对应的数据,添加对应的prefix前缀

    @ConditionalOnProperty(prefix = "spring.redis", name = "enabled", havingValue = ...