题目地址:

pid=4280">http://acm.hdu.edu.cn/showproblem.php?

pid=4280

这个题是一个纯最大流模板题。。就是用来卡时间的。。

还好我会isap算法。。可是坑爹的是一直WA。最后加了个输入优化就过了。。。(不过把输入改了改而已。

)至今不知道为什么。。请好心的看到此博客的大神赐教。。

代码例如以下:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
int head[210000], s, t, nv, maxint=0x3f3f3f3f, cnt;
int cur[210000], pre[210000], q[5000000], d[210000], num[210000];
struct node
{
int u, v, cap, next;
}edge[11000000];
void add(int u, int v, int cap)
{
edge[cnt].v=v;
edge[cnt].cap=cap;
edge[cnt].next=head[u];
head[u]=cnt++; edge[cnt].v=u;
edge[cnt].cap=cap;
edge[cnt].next=head[v];
head[v]=cnt++;
}
void bfs()
{
memset(num,0,sizeof(num));
memset(d,-1,sizeof(d));
int f1=0, f2=0, i;
q[f1++]=t;
d[t]=0;
num[0]=1;
while(f1>=f2)
{
int u=q[f2++];
for(i=head[u];i!=-1;i=edge[i].next)
{
int v=edge[i].v;
if(d[v]==-1)
{
d[v]=d[u]+1;
num[d[v]]++;
q[f1++]=v;
}
}
}
}
void isap()
{
memcpy(cur,head,sizeof(cur));
int flow=0, u=pre[s]=s, i;
bfs();
while(d[s]<nv)
{
if(u==t)
{
int f=maxint, pos;
for(i=s;i!=t;i=edge[cur[i]].v)
{
if(f>edge[cur[i]].cap)
{
f=edge[cur[i]].cap;
pos=i;
}
}
for(i=s;i!=t;i=edge[cur[i]].v)
{
edge[cur[i]].cap-=f;
edge[cur[i]^1].cap+=f;
}
flow+=f;
//printf("--");
u=pos;
}
for(i=cur[u];i!=-1;i=edge[i].next)
{
if(d[edge[i].v]+1==d[u]&&edge[i].cap)
{
break;
}
}
if(i!=-1)
{
cur[u]=i;
pre[edge[i].v]=u;
u=edge[i].v;
}
else
{
if(--num[d[u]]==0) break;
int mind=nv+1;
for(i=head[u];i!=-1;i=edge[i].next)
{
if(mind>d[edge[i].v]&&edge[i].cap)
{
mind=d[edge[i].v];
cur[u]=i;
}
}
d[u]=mind+1;
num[d[u]]++;
u=pre[u];
}
}
printf("%d\n",flow);
}
int read(){
int flag = 0, x = 0;
char ch = ' ';
while(ch != '-' && (ch > '9' || ch < '0')) ch = getchar();
if(ch == '-') flag = 1, ch = getchar();
while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return flag ? -x : x;
}
int main()
{
int T, n, m, i, j, a, b, c, x, y, min1, max1;
scanf("%d",&T);
while(T--)
{
memset(head,-1,sizeof(head));
cnt=0;
n=read();m=read();
min1=999999;
max1=-999999;
for(i=1;i<=n;i++)
{
x=read();y=read();
if(min1>x)
{
min1=x;
s=i;
}
if(max1<x)
{
max1=x;
t=i;
}
}
while(m--)
{
a=read();
b=read();
c=read();
add(a,b,c);
}
nv=n+1;
isap();
}
return 0;
}

HDU 4280Island Transport(网络流之最大流)的更多相关文章

  1. HDU 3667 Transportation(网络流之费用流)

    题目地址:HDU 3667 这题的建图真是巧妙...为了保证流量正好达到k.须要让每一次增广到的流量都是1,这就须要把每一条边的流量都是1才行.可是每条边的流量并非1,该怎么办呢.这个时候能够拆边,反 ...

  2. HDU 4280Island Transport(Dinc非STL 模板)

    题意: n岛m条路,然后是 n个岛的坐标,然后是m条双向路,包括 岛和 岛 之间 最大客流量,让求 最左边的岛 到右边的岛 最大客流量 分析: 建图 以 左边的岛为原点,最右边的为终点求最大客流量. ...

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

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

  4. HDU 4289 Control (网络流,最大流)

    HDU 4289 Control (网络流,最大流) Description You, the head of Department of Security, recently received a ...

  5. HDU 3416 Marriage Match IV (最短路径,网络流,最大流)

    HDU 3416 Marriage Match IV (最短路径,网络流,最大流) Description Do not sincere non-interference. Like that sho ...

  6. HDU 3605 Escape (网络流,最大流,位运算压缩)

    HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not ...

  7. HDU 3338 Kakuro Extension (网络流,最大流)

    HDU 3338 Kakuro Extension (网络流,最大流) Description If you solved problem like this, forget it.Because y ...

  8. POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)

    POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...

  9. HDU 4292 Food (网络流,最大流)

    HDU 4292 Food (网络流,最大流) Description You, a part-time dining service worker in your college's dining ...

随机推荐

  1. gdb 与函数过程

    http://www.lenky.info/archives/2013/02/2202

  2. Effective JavaScript Item 51 在类数组对象上重用数组方法

    Array.prototype对象上的标准方法被设计为也能够在其他对象上重用 - 即使不是继承自Array的对象. 因此,在JavaScript中存折一些类数组对象(Array-like Object ...

  3. bash中的浮点数处理

        Bash中的变量没有数据类型的定义,这样,在处理字符串和数值时会带来麻烦.例如,使用-eq比较数值,==比较字符串等.另外,Bash中常用的let.expr仅支持整数运算,不支持浮点数计算.要 ...

  4. jQuery EasyUI API 中文文档 - Panel面板

    <html> <head> <title>布局管理器--控制面板</title> <script src="jquery-easyui/ ...

  5. 批量删除linux的文件;find方法批量删除文件;find查找某时间段内的所有文件

    1.如图所示,有大量文件夹,想批量删除它们 2.使用命令 find . -maxdepth 1  -regex ".*ws.*" 可以批量找到他们.maxdepth值为1表示只在当 ...

  6. iOS:CoreData数据库的使用一(创建单个数据库表)

    CoreData数据库框架:mac系统自带的数据库,它是苹果公司对sqlite进行封装而来的,既提供了对数据库的主要操作,也提供了具体的视图关系模型. 需要用到三个对象: 1•Managed Obje ...

  7. JNI/NDK开发指南(十)——JNI局部引用、全局引用和弱全局引用

    转自:http://blog.csdn.net/xyang81/article/details/44657385   这篇文章比较偏理论,详细介绍了在编写本地代码时三种引用的使用场景和注意事项.可能看 ...

  8. [Todo]对于thrift和protobuf比较好的描述

    比较跨语言通讯框架:thrift和Protobuf 全部thrift protobuf 前两天想在微博上发表一个观点:在现在的技术体系中,能用于描述通讯协议的方式很多,xml,json,protobu ...

  9. CC+语言 struct 深层探索——CC + language struct deep exploration

    1        struct 的巨大作用 面对一个人的大型C/C++程序时,只看其对struct 的使用情况我们就可以对其编写者的编程经验进行评估.因为一个大型的C/C++程序,势必要涉及一些(甚至 ...

  10. go语言基础之函数类型

    1.函数类型 示例: package main import "fmt" func Add(a, b int) int { return a + b } func main() { ...