裸的网络流,递归的dinic会爆栈,在第一行加一句就行了

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <algorithm>
#include <vector>
#define Maxn 120010
#define Maxm 210000
#define LL int
#define inf 100000000
#define Abs(a) (a)>0?(a):(-a)
using namespace std;
struct Edge{
int from,to,next;
LL val;
}edge[Maxm];
const double eps=1e-;
LL value[Maxn];
int head[Maxn],work[Maxn],dis[Maxn],q[Maxn],e,vi[Maxn];
void init()
{
e=;
memset(head,-,sizeof(head));
}
void add(int u,int v,LL c)//有向边
{
edge[e].to=v;edge[e].val=c;edge[e].next=head[u];head[u]=e++;
edge[e].to=u;edge[e].val=c;edge[e].next=head[v];head[v]=e++;
}
int bfs(int S,int T)
{
int rear=;
memset(dis,-,sizeof(dis));
dis[S]=;q[rear++]=S;
for(int i=;i<rear;i++)
{
for(int j=head[q[i]];j!=-;j=edge[j].next)
{
if(edge[j].val&&dis[edge[j].to]==-)
{
dis[edge[j].to]=dis[q[i]]+;
q[rear++]=edge[j].to;
if(edge[j].to==T) return ;
}
}
}
return ;
}
LL dfs(int cur,LL a,int T)
{
if(cur==T) return a;
for(int &i=work[cur];i!=-;i=edge[i].next)
{
if(edge[i].val&&dis[edge[i].to]==dis[cur]+)
{
LL t=dfs(edge[i].to,min(a,edge[i].val),T);
if(t)
{
edge[i].val-=t;
edge[i^].val+=t;
return t;
}
}
}
return ;
}
LL Dinic(int S,int T)
{
LL ans=;
while(bfs(S,T))
{
memcpy(work,head,sizeof(head));
while(LL t=dfs(S,inf,T)) ans+=t;
}
return ans;
}
int main()
{
int n,m,i,j,num=,t,a,b,west=,east=-,S,T;
LL c;
scanf("%d",&t);
while(t--)
{
init();
west=,east=-;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
{
scanf("%d%d",&a,&b);
if(a<west)
west=a,S=i;
if(a>east)
east=a,T=i;
}
for(i=;i<=m;i++)
{
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
}
LL ans=Dinic(S,T);
printf("%d\n",ans);
}
return ;
}

hdu 4280 网络流的更多相关文章

  1. HDU 4280 Island Transport(网络流,最大流)

    HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...

  2. 【解题报告】 Leapin' Lizards HDU 2732 网络流

    [解题报告] Leapin' Lizards HDU 2732 网络流 题外话 在正式讲这个题目之前我想先说几件事 1. 如果大家要做网络流的题目,我在网上看到一个家伙,他那里列出了一堆网络流的题目, ...

  3. HDU 4280 Island Transport(无向图最大流)

    HDU 4280:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意: 比较裸的最大流题目,就是这是个无向图,并且比较卡时间. 思路: 是这样的,由于是 ...

  4. HDU 4280 Island Transport(网络流)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=4280">http://acm.hdu.edu.cn/showproblem.php ...

  5. (网络流) Island Transport --Hdu -- 4280

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=4280 源点是West, 汇点是East, 用Dinic带入求就好了 代码:要用c++提交 #pragma ...

  6. HDU 4280 Island Transport

    Island Transport Time Limit: 10000ms Memory Limit: 65536KB This problem will be judged on HDU. Origi ...

  7. HDU 4280:Island Transport(ISAP模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...

  8. hdu 4280 最大流

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 #pragma comment(linker, "/STACK:1024000000, ...

  9. HDU 1083 网络流之二分图匹配

    http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...

随机推荐

  1. 修复Debian(Ubuntu)Grub2 引导

    重装win7, 之前的系统debian 的引导就没有了. 而debian 的盘似乎没有ubuntu的livecd模式,于是用ultraISO将ubuntu的ios文件写入到u盘中. boot时选择启动 ...

  2. POJ 2502 Subway (最短路)

    Subway 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/L Description You have just moved ...

  3. HDU 1856 More is better(并查集)

    http://acm.hdu.edu.cn/showproblem.php?pid=1856 More is better Time Limit: 5000/1000 MS (Java/Others) ...

  4. 如何解决paramiko执行与否的问题

    使用paramiko执行一些耗时比较长的命令的时候会出现实际上命令没有执行完就跳出的问题,怎么才能准确的判断命令执行完与否很重要,通过试验发现如下的方法可以解决这个难题: dabao_cmd = 'e ...

  5. opencv 模板匹配与滑动窗口(单匹配) (多匹配)

    1单匹配: 测试图片:   code: #include <opencv\cv.h> #include <opencv\highgui.h> #include <open ...

  6. ASP.NET MVC- 数据验证机制

    ASP.NET MVC的数据验证机制,比起ASP.NET WEBFORM那种高效很多.下面记录以下两个示例,以便日后方便查阅. 方式一:在Controller里通过AddModelError方法返回错 ...

  7. 使用jdk操作 wsdl2java (wedservice)

    打开jdk下的bin目录 看下能否找到"wsimport.exe"这个文件 一般情况下都会有 如果没有则说明你的JDK不支持这个功能 然后在DOS窗口下输入wsimport 敲回车 ...

  8. UVa 112 Tree Summing

    题意: 计算从根到叶节点的累加值,看看是否等于指定值.是输出yes,否则no.注意叶节点判断条件是没有左右子节点. 思路: 建树过程中计算根到叶节点的sum. 注意: cin读取失败后要调用clear ...

  9. EasyUI基础入门之Parser(解析器)

    前言 JQuery EasyUI提供的组件包含功能强大的DataGrid,TreeGrid.面板.下拉组合等.用户能够组合使用这些组件,也能够单独使用当中一个.(使用的形式是以插件的方式提供的) Ea ...

  10. Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树

    C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...