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. Webpack将静态资源拷贝并压缩至输出文件夹

    就拿Vue项目来说,比如要将src/assets/js下的静态js文件,直接在public/index.html中引用: 这时候没有在项目中引用,不会经过wenpack的loader,也就不会自己打包 ...

  2. oracle update left join 写法

    oracle update left join 写法 (修改某列,条件字段在关联表中) 案例: E:考核表 X,:用户表 USERNAME 关联 需求:修改营业部最高分 分析:通过登录账号的营业部OR ...

  3. JS 中document.write()的用法和清空的原因浅析(转)

    转自:https://www.jb51.net/article/129715.htm

  4. css 省略号的写法

    单行省略号 overflow: hidden; text-overflow:ellipsis; white-space: nowrap; width:500px; 多行省略号 overflow: hi ...

  5. 浅学CLR via C#笔记之类型转换

    我们都知道CLR最重要的一个特性就是类型安全,它在运行时就知道对象类型. 但我们会经常用到将一种类型转换成另一种类型,CLR也允许将对象转成他的实际类型,或者是它的基类型. 在C#中,支持隐士转换成它 ...

  6. 关于MQ的几件小事(五)如何保证消息按顺序执行

    1.为什么要保证顺序 消息队列中的若干消息如果是对同一个数据进行操作,这些操作具有前后的关系,必须要按前后的顺序执行,否则就会造成数据异常.举例: 比如通过mysql binlog进行两个数据库的数据 ...

  7. nginx日志文件的配置

    文章来源 运维公会: nginx日志文件的配置 1.日志介绍 nginx有两种日志,一种是访问日志,一种是错误日志. 访问日志中记录的是客户端对服务器的所有请求. 错误日志中记录的是在访问过程中,因为 ...

  8. C# 中的匿名函数使用

    需求:在图一的callback函数中,我需要使用4个参数,但是又不想把四个参数都传入到requestImg 里面,可以采用上面的 匿名函数的做法.

  9. MVC-路由(Route)

    1.启用路由前的准备工作 Global.asax.cs中注册路由 public class MvcApplication : System.Web.HttpApplication { protecte ...

  10. Linux 之 搜索

    locate - 文件名搜索命令 用于查找文件 格式为:locate 文件名 该命令用于查找符合条件的文件,它会去保存文件与目录名称的数据库内,查找合乎范本样式条件的文件或目录. 因为该命令是直接在数 ...