【模板】网络流模板

好吧我只会最大流

dinic

 1 int n,m,s,t,cnt=1;
 2 int last[1005];
 3 int h[1005],q[1005];
 4 struct edge {
 5     int next,v,to;
 6 } e[100005];
 7 void insert(int u,int v,int w) {
 8     e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;e[cnt].v=w;
 9     e[++cnt].to=u;e[cnt].next=last[v];last[v]=cnt;e[cnt].v=0;
10 }
11 bool bfs(int s,int t) {
12     int head=0,tail=1;
13     memset(h,-1,sizeof(h));
14     q[0]=s,h[0]=0;
15     while(head!=tail) {
16         int now=q[head];
17         head++;
18         for(int i=last[now]; i; i=e[i].next)
19             if(e[i].v&&h[e[i].to]==-1) {
20                 h[e[i].to]=h[now]+1;
21                 q[tail++]=e[i].to;
22             }
23     }
24     return h[t]!=-1;
25 }
26 int dfs(int x,int t,int f) {
27     if(x==t)
28         return f;
29     int w,used=0;
30     for(int i=last[x]; i; i=e[i].next)
31         if(h[e[i].to]==h[x]+1) {
32             w=dfs(e[i].to,t,min(f-used,e[i].v));
33             e[i].v-=w;
34             e[i^1].v+=w;
35             used+=w;
36             if(used==f)return f;
37         }
38     if(!used)h[x]=-1;
39     return used;
40 }
41 int dinic(int s,int t) {
42     int tmp=0;
43     while(bfs(s,t))
44         tmp+=dfs(s,t,inf);
45     return tmp;
46 }

RP++

时间: 2024-06-16 20:13:14

【模板】网络流模板的相关文章

Kuangbin网络流模板

Kuangbin网络流模板. const int maxn=20010; const int maxm=200010; const double INF=1e20; const double eps=1e-8; struct Edge{ int to,next; double cap,flow; }edge[maxm],tmpG[maxm]; int n,tot,toth,totv; int head[maxn],tmph[maxn]; int gap[maxn],dep[maxn],cur[m

HDU 4280 Island Transport(网络流模板)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 Problem Description In the vast waters far far away, there are many islands. People are living on the islands, and all the transport among the islands relies

模板系列(一) 模板的模板参数

前面我们写过类似的Stack: template <typename T, typename Alloc = std::vector<T> > class Stack { public: void push(const T &); void pop(); T top() const; bool empty() const; private: Alloc _cont; }; 那么我们使用的时候需要这样: Stack<string, list<string>

畅通工程续 (SPFA模板Floy模板)

http://acm.hdu.edu.cn/showproblem.php?pid=1874 SPFA #include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #define N 1000001 using namespace std; int n,m; int v[202],dis[202]; struct node { int x,y,z,next; }

Struts2中使用Velocity模板时模板资源路径配置问题

在Struts2中使用Velocity模板时,如何以相对与Web工程的路径来配置模板资源文件路径这个问题网上千篇一律的来自Velocity官方文档.官方文档中指出如果是Web工程的话,模板的相对路径是工程根路径,今天在使用的时候有如下配置: Velocity.properties(默认在WEB-INF下): resource.loader =file, classclass.resource.loader.description = Velocity Classpath Resource Loa

C++提高1 【泛型编程】函数模板 类模板

[本文谢绝转载] [泛型编程] 函数模板 为什么会有函数模板 现象: 函数的业务逻辑一样 函数的参数类型不一样 [最常用]函数模板  显式的调用 [不常用]类型推导 多个参数,参数定义了必须要用 函数模板,实现int类型数组,char字符串排序: 函数模板 与 普通函数的本质区别 函数模板 和 普通函数在一起 的调用型研究: C++是如何支持函数模板机制的? 函数模板机制结论 类模板 类模板的定义 类模板做函数的参数 类模板的派生成普通类 模板类的派生成模板类 复数类,所有函数都写在类的内部,运

C++:类模板与模板类

6.3 类模板和模板类 所谓类模板,实际上是建立一个通用类,其数据成员.成员函数的返回值类型和形参类型不具体指定,用一个虚拟的类型来代表.使用类模板定义对象时,系统会实参的类型来取代类模板中虚拟类型从而实现了不同类的功能. 定义一个类模板与定义函数模板的格式类似,必须以关键字template开始,后面是尖括号括起来的模板参数,然后是类名,其格式如下: template <typename 类型参数> class 类名{       类成员声明 }; 或者 template <class

函数模板 类模板

摘要:学习函数模板的定义,使用:学习类模板的定义和使用. 函数模板: template <typename 类型参数> 返回类型 函数名(模板形参表) { 函数体 } 特点:1.函数模板可以重载(比如形参数量不同的情况). 2.定义的时候,template <typename 类型参数>到下面一个语句之间不允许插入其他语句! 3.如果程序中有和函数模板名称相同的非函数模板函数,则优先调用它. 例子: #include<iostream> using namespace

Flask Web Development - Flask 模板1 - 模板机制&Jinja2引擎

节选自PartI Chapter3,这个chapter主要讲模板工作原理,这里讲的就是Jinja2这个模板,另外还提到了Flask-Bootstrap及Flask-Moment两个插件,前者对Flask使用Bootstrap做了些封装,后者对moment.js做了些封装.内容较多,估计分开搞. 模板存在的意义 可维护性高的代码是结构良好且整洁的. 当用户在网站注册一个账户时,他在表单里填入邮箱跟密码,并点击提交按钮.在server端就收到一个包含这些数据的request,再由Flask分发到相应

模板(二) 模板语法

一.模板参数列表 模板参数列表是一个逗号分隔的一个或者多个模板参数的列表: template<typename T, typename U> 如上所示,typename T和typename U为模板参数: 二.模板参数 模板参数分为模板类型参数与非类型模板参数两种: 1)模板类型参数:模板类型参数可以看做类型说明符,可以向类类型说明符和内置类型一样使用: 2)非类型模板参数:非类型模板参数可以是一个整型,或者一个指向对象或者函数类型的指针或引用:非类型模板参数用来表示一个值, 需要通过一个特