【网络流】【Dinic】【最大流】bzoj3396 [Usaco2009 Jan]Total flow 水流
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
#define INF 2147483647
#define MAXN 201
#define MAXM 1501
int v[MAXM],cap[MAXM],en,first[MAXN],next[MAXM];
int d[MAXN],cur[MAXN];
queue<int>q;
int m,S,T,W;
char U[],V[];
void Init_Dinic(){memset(first,-,sizeof(first)); en=; S='A'; T='Z';}
void AddEdge(const int &U,const int &V,const int &W)
{v[en]=V; cap[en]=W; next[en]=first[U]; first[U]=en++;
v[en]=U; next[en]=first[V]; first[V]=en++;}
bool bfs()
{
memset(d,-,sizeof(d)); q.push(S); d[S]=;
while(!q.empty())
{
int U=q.front(); q.pop();
for(int i=first[U];i!=-;i=next[i])
if(d[v[i]]==- && cap[i])
{
d[v[i]]=d[U]+;
q.push(v[i]);
}
}
return d[T]!=-;
}
int dfs(int U,int a)
{
if(U==T || !a) return a;
int Flow=,f;
for(int &i=cur[U];i!=-;i=next[i])
if(d[U]+==d[v[i]] && (f=dfs(v[i],min(a,cap[i]))))
{
cap[i]-=f; cap[i^]+=f;
Flow+=f; a-=f; if(!a) break;
}
if(!Flow) d[U]=-;
return Flow;
}
int max_flow()
{
int Flow=,tmp=;
while(bfs())
{
memcpy(cur,first,sizeof(cur));
while(tmp=dfs(S,INF)) Flow+=tmp;
}
return Flow;
}
int main()
{
scanf("%d",&m); Init_Dinic();
for(int i=;i<=m;++i)
{
scanf("%s%s%d",U,V,&W);
AddEdge(U[],V[],W);
}
printf("%d\n",max_flow());
return ;
}
【网络流】【Dinic】【最大流】bzoj3396 [Usaco2009 Jan]Total flow 水流的更多相关文章
- BZOJ3396: [Usaco2009 Jan]Total flow 水流
3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 45 Solved: 27[Sub ...
- 3396: [Usaco2009 Jan]Total flow 水流
3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 179 Solved: 73[Su ...
- bzoj 3396: [Usaco2009 Jan]Total flow 水流【最大流】
最大流生动形象的板子,注意数组开大点 #include<iostream> #include<cstdio> #include<queue> #include< ...
- 【BZOJ】3396: [Usaco2009 Jan]Total flow 水流 (最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=3396 裸的最大流跑过.. #include <cstdio> #include < ...
- 网络流之最大流Dinic算法模版
/* 网络流之最大流Dinic算法模版 */ #include <cstring> #include <cstdio> #include <queue> using ...
- 网络流之最大流Dinic --- poj 1459
题目链接 Description A power network consists of nodes (power stations, consumers and dispatchers) conne ...
- UVA 10480 Sabotage (网络流,最大流,最小割)
UVA 10480 Sabotage (网络流,最大流,最小割) Description The regime of a small but wealthy dictatorship has been ...
- [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
- 【Luogu2711】小行星(网络流,最大流)
[Luogu2711]小行星(网络流,最大流) 题面 题目描述 星云中有n颗行星,每颗行星的位置是(x,y,z).每次可以消除一个面(即x,y或z坐标相等)的行星,但是由于时间有限,求消除这些行星的最 ...
随机推荐
- POJ 1050 To the Max 二维最大子段和
To the MaxTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 52281 Accepted: 27633Description ...
- Death Note
注:本文系作者原创,但可随意转载. ********************************************************************************** ...
- barba 页面渲染
a.css html, body { padding:; margin: 0 } ol.menu { width: 100%; text-align: left; padding: 0 !import ...
- Linux Top 命令参数解析
转载自:http://www.jb51.net/LINUXjishu/34604.html TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户 ...
- Spring 学习笔记(一)
一.Spring 是什么? •Spring 是一个开源框架. •Spring 为简化企业级应用开发而生. 使用 Spring 可以使简单的 JavaBean 实现以前只有 EJB 才能实现的功能. • ...
- bzoj 3100 排列
题目大意: 给你长度为 \(1e6\) 的序列, 求最大的 \(K\) 使得序列中含有一个 \(K\) 的排列 做法: 性质: 区间包含1, 元素不重, 区间最大值=区间长度 枚举一个 \(1\) 让 ...
- request.getParameterValues与request.getParameter的区别
一. 简单的对比 request.getParameter用的比较多,相对熟悉 request.getParameterValues(String name)是获得如checkbox类(名字相同, ...
- [FZU2261]浪里个浪
TonyY是一个喜欢到处浪的男人,他的梦想是带着兰兰姐姐浪遍天朝的各个角落,不过在此之前,他需要做好规划. 现在他的手上有一份天朝地图,上面有n个城市,m条交通路径,每条交通路径都是单行道.他已经预先 ...
- 转:selenium webdriver+python基本操作
转自: http://blog.163.com/ly676830315@126/blog/static/1017337222013102310617946/ 导入模块: from selenium i ...
- 汉字hash问题(转)
一.汉字编码的种类 汉字编码中现在主要用到的有三类,包括GBK,GB2312和Big5. 1.GB2312又称国标码,由国家标准总局发布,1981年5月1日实施,通行于大陆.新加坡等地也使用此编码.它 ...