hdu 4280 网络流
裸的网络流,递归的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 网络流的更多相关文章
- HDU 4280 Island Transport(网络流,最大流)
HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...
- 【解题报告】 Leapin' Lizards HDU 2732 网络流
[解题报告] Leapin' Lizards HDU 2732 网络流 题外话 在正式讲这个题目之前我想先说几件事 1. 如果大家要做网络流的题目,我在网上看到一个家伙,他那里列出了一堆网络流的题目, ...
- HDU 4280 Island Transport(无向图最大流)
HDU 4280:http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意: 比较裸的最大流题目,就是这是个无向图,并且比较卡时间. 思路: 是这样的,由于是 ...
- HDU 4280 Island Transport(网络流)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=4280">http://acm.hdu.edu.cn/showproblem.php ...
- (网络流) Island Transport --Hdu -- 4280
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4280 源点是West, 汇点是East, 用Dinic带入求就好了 代码:要用c++提交 #pragma ...
- HDU 4280 Island Transport
Island Transport Time Limit: 10000ms Memory Limit: 65536KB This problem will be judged on HDU. Origi ...
- HDU 4280:Island Transport(ISAP模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...
- hdu 4280 最大流
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280 #pragma comment(linker, "/STACK:1024000000, ...
- HDU 1083 网络流之二分图匹配
http://acm.hdu.edu.cn/showproblem.php?pid=1083 二分图匹配用得很多 这道题只需要简化的二分匹配 #include<iostream> #inc ...
随机推荐
- Spring AOP Example – Pointcut , Advisor
In last Spring AOP advice examples, the entire methods of a class are intercepted automatically. But ...
- [置顶] 《Windows编程零基础》__2 一个完整的程序
Windows开发的常识 1)窗口 Windows中最基本的概念也许就是窗口了,每一个前台程序都至少有一个窗口,一个窗口也是你可以看到的部分,比如,QQ有如下的登录窗口 基本上你在Windows中可见 ...
- 教你50招提升ASP.NET性能(十七):不要认为问题只会从业务层产生
(28)Don’t assume that problems can only arise from business logic 招数28: 不要认为问题只会从业务层产生 When beginnin ...
- CentOS 6系统下安装 JDK1.6
CentOS 6系统下安装 JDK1.6 JDK(Java Development Kit)是Sun Microsystems针对Java开发员的产品.自从Java推出以来,JDK已经成为使用最广泛的 ...
- PL/pgSQL学习笔记之一
开始 资料来源:http://www.postgresql.org/docs/9.1/static/plpgsql-overview.html 39.1 概要: PL/pgSQL是一种可载入的过程语言 ...
- 有关java中static关键的重写问题
<Java编程思想>中这样提到“只有普通的方法调用可以是多态的”.说白了,就是静态方法不能实现重写这种多态. JAVA静态方法形式上可以重写(只要子类不加@Override关键字修饰的话, ...
- 怎么去掉li标签前面的点??
<ul class="list"> <li> </li> <li> </li> </ul> .list li ...
- Codeforces Round #185 (Div. 2) A. Whose sentence is it? 水题
A. Whose sentence is it? Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/ ...
- 套题 Codeforces Round #277 (Div. 2)
A. Calculating Function 水题,分奇数偶数处理一下就好了 #include<stdio.h> #include<iostream> using names ...
- uoj #31. 【UR #2】猪猪侠再战括号序列 贪心
#31. [UR #2]猪猪侠再战括号序列 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/31 Descript ...