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. Oracle通过ODBC链接SqlServer数据库

    原网址:https://www.cnblogs.com/jijm123/p/11598515.html 第一步.创建ODBC数据源 这一步要考虑数据源是32位还是64位的问题,其实就是选择不同的exe ...

  2. hdu1501 记忆化搜索。。。

    Problem Description Given three strings, you are to determine whether the third string can be formed ...

  3. 【转载】Spring JdbcTemplate详解

    JdbcTemplate简介 Spring对数据库的操作在jdbc上面做了深层次的封装,使用spring的注入功能,可以把DataSource注册到JdbcTemplate之中. JdbcTempla ...

  4. Go 操作 Mysql(三)

    什么是事务? 事务是数据库非常重要的部分,它具有四大特性(原子性.一致性.隔离性.持久性) 以下内容出自<高性能MySQL>第三版,了解事务的ACID及四种隔离级有助于我们更好的理解事务运 ...

  5. 【转载】C#中使用OrderBy和ThenBy等方法对List集合进行排序

    在C#的List操作中,针对List对象集合的排序我们可以使用OrderBy.OrderByDescending.ThenBy.ThenByDescending等方法按照特定的对象属性进行排序,其中O ...

  6. S5PV210 启动流程

    S3C6410启动流程 首先,看一下S3C6410启动流程 ① iROM supports initial boot up : initialize system clock, D-TCM, devi ...

  7. STM8 LED

    时钟分频寄存器(CLK_CKDIVR) 举例 int main() { CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); //高速内部时钟1分频 GPIO_ ...

  8. Android简单闹钟设置

    利用AlarmManager实现闹钟设置 //设置本地闹钟,actiongString:闹钟标识 setLocAlarm(int week, String actionString) { Calend ...

  9. Java软件编码习惯

    1.再删除某个类时候,一定别忘记把对应的import也删除掉: 可以手动删除,也可以 Ctrl+Shift+O快捷键自动删除和导入.

  10. Linux软件包(源码包和二进制包)及其区别和特点

    Linux 下的软件包众多,而且几乎都是经 GPL 授权的,也就是说这些软件都免费,振奋人心吧?而且更棒的是,这些软件几乎都提供源代码(开源的),只要你愿意,就可以修改程序源代码,以符合个人的需求和习 ...