链接:

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

源点是West, 汇点是East, 用Dinic带入求就好了

代码:要用c++提交

#pragma comment(linker, "/STACK:102400000,102400000")  ///手动开大栈区
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std; #define N 100005
#define INF 0x3fffffff struct node {int v, flow, next;} a[N<<]; int Layer[N], Head[N], cnt, n, m; void Init()
{
cnt = ;
memset(Head, -, sizeof(Head));
} void Add(int u, int v, int flow)
{
a[cnt].v = v;
a[cnt].flow = flow;
a[cnt].next = Head[u];
Head[u] = cnt++;
} bool BFS(int Start, int End)
{
queue<int>Q;
Q.push(Start); memset(Layer, , sizeof(Layer));
Layer[Start] = ; while(Q.size())
{
int u = Q.front(); Q.pop(); if(u==End) return true; for(int i=Head[u]; i!=-; i=a[i].next)
{
int v = a[i].v; if(!Layer[v] && a[i].flow)
{
Layer[v] = Layer[u] + ;
Q.push(v);
}
}
}
return false;
}
int DFS(int u, int MaxFlow, int End)
{
if(u==End) return MaxFlow; int uflow=; for(int i=Head[u]; i!=-; i=a[i].next)
{
int v = a[i].v;
if(Layer[v]==Layer[u]+ && a[i].flow)
{
int flow = min(a[i].flow, MaxFlow-uflow);
flow = DFS(v, flow, End); a[i].flow -= flow;
a[i^].flow += flow;
uflow += flow; if(uflow==MaxFlow) break;
}
} if(uflow==) Layer[u] = ; return uflow;
}
int Dinic(int Start, int End)
{
int MaxFlow=; while(BFS(Start, End)==true)
MaxFlow += DFS(Start, INF, End); return MaxFlow;
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int i, u, v, flow, East=-INF, West=INF, Start, End, x, y; scanf("%d%d", &n, &m); Init();
for(i=; i<=n; i++)
{
scanf("%d%d", &x, &y);
if(West > x)
{
West = x;
Start = i;
}
if(East < x)
{
East = x;
End = i;
}
} for(i=; i<=m; i++)
{
scanf("%d%d%d", &u, &v, &flow);
Add(u, v, flow);
Add(v, u, flow);
} printf("%d\n", Dinic(Start, End));
}
return ;
}

(网络流) Island Transport --Hdu -- 4280的更多相关文章

  1. G - Island Transport - hdu 4280(最大流)

    题意:有N个岛屿,M条路线,每条路都连接两个岛屿,并且每条路都有一个最大承载人数,现在想知道从最西边的岛到最东面的岛最多能有多少人过去(最西面和最东面的岛屿只有一个). 分析:可以比较明显的看出来是一 ...

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

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

  3. HDU 4280 Island Transport

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

  4. Hdu 4280 Island Transport(最大流)

    Island Transport Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

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

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

  6. HDU 4280 Island Transport(dinic+当前弧优化)

    Island Transport Description In the vast waters far far away, there are many islands. People are liv ...

  7. Island Transport

    Island Transport http://acm.hdu.edu.cn/showproblem.php?pid=4280 Time Limit: 20000/10000 MS (Java/Oth ...

  8. HDU4280:Island Transport(最大流)

    Island Transport Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

  9. HDU 4280 ISAP+BFS 最大流 模板

    Island Transport Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Other ...

随机推荐

  1. 一行转多行 及多行转一行的 hive语句

      注意 :|,: 是特殊符号,要用 "\\|", "\\;"来表示.   一行转多行 usertags 里面有很多项,每项之间以逗号分隔   create t ...

  2. HTML 练习 做简历表

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 常用mysql text 类型,varchar最大长度

    MySQL 3种text类型的最大长度如下: TEXT 65,535 bytes ~64kb MEDIUMTEXT 16,777,215 bytes ~16Mb LONGTEXT 4,294,967, ...

  4. SQLserver和oracle中对应的数据类型

  5. appium + python的环境配置_windows

    appium是什么? 1,appium是开源的移动端自动化测试框架: 2,appium可以测试原生的.混合的.以及移动端的web项目: 3,appium可以测试ios,android应用(当然了,还有 ...

  6. eclipse搭建struts2环境及所遇到的问题

    最近几天一直在搭建struts2框架,本身struts2框架的搭建是非常简单的,但不知道为什么最近就是总是报错,报了一大串的错 首先就是每次在类的根路径下创建struts.xml时,就报错,也不知道为 ...

  7. UVa 1595 Symmetry(set)

    We call a figure made of points is left-right symmetric as it is possible to fold the sheet of paper ...

  8. html标签的总结-重复

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. runloop 和 CFRunLoop - 定时器 - NSTimer 和 GCD定时器

    1. 2. #import "ViewController.h" @interface ViewController () @property (nonatomic, strong ...

  10. [leetcode]158. Read N Characters Given Read4 II - Call multiple times 用Read4读取N个字符2 - 调用多次

    The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...