#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cstdlib>
#include<string>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=0.00000001;
const int N=60100;
struct node{
int to,next;
int flow;
}edge[N*10];
int head[N];
int dis[N];
int tot;
void init(){
memset(head,-1,sizeof(head));
tot=0;
}
void add(int u,int v,int flow){
edge[tot].to=v;
edge[tot].flow=flow;
edge[tot].next=head[u];
head[u]=tot++; edge[tot].to=u;
edge[tot].flow=0;
edge[tot].next=head[v];
head[v]=tot++;
}
int BFS(int s,int t){
queue<int>q;
memset(dis,-1,sizeof(dis));
q.push(s);
dis[s]=0;
while(q.empty()==0){
int u=q.front();
q.pop();
for(int i=head[u];i!=-1;i=edge[i].next){
int v=edge[i].to;
if(dis[v]==-1&&edge[i].flow){
dis[v]=dis[u]+1;
q.push(v);
}
}
}
if(dis[t]==-1)return 0;
return 1;
}
int DFS(int s,int t,int flow){
if(s==t)return flow;
int ans=0;
for(int i=head[s];i!=-1;i=edge[i].next){
int v=edge[i].to;
if(edge[i].flow&&dis[v]==dis[s]+1){
int f=DFS(v,t,min(flow-ans,edge[i].flow));
edge[i].flow=edge[i].flow-f;
edge[i^1].flow=edge[i^1].flow+f;
ans=ans+f;
if(flow==ans)return flow;
}
}
if(ans==0)dis[s]=-1;
return ans;
}
int Dinc(int s,int t){
int flow=0;
while(BFS(s,t)){
flow+=DFS(s,t,INF);
}
return flow;
}

不再作死了

Dinic(模板 再错是不可能的 这辈子都不可能了)的更多相关文章

  1. hdu 1532 Dinic模板(小白书)

    hdu1532 输入n,m. n条边,m个点,之后给出a到b的容量,求1到m的最大流. 注意:Dinic只能调用一次,因为原理是改变cap的值,如果调用多次一样的,那么第一次会对,其余的都会是0,因为 ...

  2. 最大流算法 ISAP 模板 和 Dinic模板

    ISAP // UVa11248 Frequency Hopping:使用ISAP算法,加优化 // Rujia Liu struct Edge { int from, to, cap, flow; ...

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

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

  4. 洛谷P3376【模板】网络最大流  Dinic模板

    之前的Dinic模板照着刘汝佳写的vector然后十分鬼畜跑得奇慢无比,虽然别人这样写也没慢多少但是自己的就是令人捉急. 改成邻接表之后快了三倍,虽然还是比较慢但是自己比较满意了.虽然一开始ecnt从 ...

  5. [Selenium]等待元素出现之后再消失,界面上的loading icon都属于这种类型,之前的方法总是卡死,换这种方法目前还好用的

    等待元素出现之后再消失,界面上的loading icon都属于这种类型,之前的方法总是卡死,换这种方法目前还好用的 /** * Check if the element present with cu ...

  6. SMW0上传EXCEL模板时报错无分配给对象***的MIME类型

    在使用SMW0上传照片.声音文件.EXCEL模板等文件时,遇到报错提示,如下图所示: 解决办法:需要先维护 .XLS 文件的MIME TYPE,SMW0 打开如下图所示 选择上图红色框中“WebRFC ...

  7. freemarker解析模板报错问题

    在确定模板文件代码无误的情况下,导致报错的原因大概有以下原因: 模板文件编码改变了(比如eclipse中的项目部署到tomcat下,而忘记设置tomcat编码就会导致读取模板文件编码不正确,导致程序解 ...

  8. 【网络流#3】hdu 1532 - Dinic模板题

    输入为m,n表示m条边,n个结点 记下来m行,每行三个数,x,y,c表示x到y的边流量最大为c 这道题的模板来自于网络 http://blog.csdn.net/sprintfwater/articl ...

  9. 最大流当前弧优化Dinic模板

    最大流模板: 普通最大流 无向图限制:将无向图的边拆成2条方向相反的边 无源汇点有最小流限制的最大流:理解为水管流量形成循环,每根水管有流量限制,并且流入量等于流出量 有源汇点的最小流限制的最大流 顶 ...

随机推荐

  1. Buffer.alloc()

    Buffer.alloc(size[, fill[, encoding]]) Node.js FS模块方法速查 size {Number} fill {Value} 默认:undefined enco ...

  2. build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing

    maven test项目时遇到一下错误 Some problems were encountered while building the effective model for cn.temptat ...

  3. LeetCode(88)Merge Sorted Array

    题目 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note ...

  4. Python实现图片切割

    import os from PIL import Image def splitimage(src, rownum, colnum, dstpath): img = Image.open(src) ...

  5. UVALive 6507 Passwords

    Passwords Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ...

  6. MVC系统学习6—Filter

    Mvc的过滤器是特性类,可以使我们在执行Action之前,执行Action之后,执行Action发生异常时,编写相关的处理代码实现某些逻辑.下面是四个基本的Filter接口. 上面这四个基本的Filt ...

  7. 7-26 Windows消息队列(25 分)(堆排序)

    7-26 Windows消息队列(25 分) 消息队列是Windows系统的基础.对于每个进程,系统维护一个消息队列.如果在进程中有特定事件发生,如点击鼠标.文字改变等,系统将把这个消息加到队列当中. ...

  8. [luoguP1077] 摆花(DP)

    传送门 f[i][j] 表示前 i 种花,摆 j 盆的方案数    j f[i][j] =  Σ f[i - 1][j] k=max(0, j - a[i]) 博客园这个公式该怎么打啊.. ——代码( ...

  9. idea导入(import)项目和打开(open)项目的区别

    前言: 每次接手老项目,都得从git或svn下载下来,但是如果之前的项目不是用idea写的怎么办,可是你又习惯啦idea,那你必须把项目在idea上跑起来,那是用import还是用open呢,如何抉择 ...

  10. 跪啃SAM

    struct SAM { ],size,last,pre[maxn],pos[maxn]; SAM() { size=; memset(ch[],,])); pre[]=-; } int idx(ch ...