题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4280

题意:有n个岛屿,m条无向路,每个路给出最大允许的客流量,求从最西的那个岛屿最多能运用多少乘客到最东的那个岛屿

题解:最大流的裸题。输入记得找到最西和最东的岛屿,以及注意是双向边。。这题用的sap.

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string>
#include<queue>
#include<algorithm>
using namespace std; const int N=;
const int M=;
const int inf=0xfffffff; int n,m,cnt; struct Edge{
int v , cap , next;
} edge[M]; int head[N],pre[N],d[N],numd[N];
int cur_edge[N]; void addedge(int u,int v,int c){
edge[cnt].v = v;
edge[cnt].cap = c;
edge[cnt].next = head[u];
head[u] = cnt++; edge[cnt].v = u;
edge[cnt].cap = ;
edge[cnt].next = head[v];
head[v] = cnt++;
} void bfs(int s){
memset(numd,,sizeof(numd));
for(int i=; i<=n; i++) numd[ d[i] = n ]++;
d[s] = ;
numd[n]--;
numd[]++;
queue<int> Q;
Q.push(s); while(!Q.empty()){
int v=Q.front();
Q.pop(); int i=head[v];
while(i != -){
int u=edge[i].v; if(d[u]<n){
i=edge[i].next;
continue ;
} d[u] = d[v]+;
numd[n]--;
numd[d[u]]++;
Q.push(u);
i=edge[i].next;
}
}
} int SAP(int s,int t){
for(int i = ; i <= n; i++) cur_edge[i] = head[i];
int max_flow = ;
bfs(t);
int u = s ;
while(d[s] < n){
if(u == t){
int cur_flow = inf,neck;
for(int from = s; from != t; from = edge[cur_edge[from]].v){
if(cur_flow > edge[cur_edge[from]].cap){
neck = from;
cur_flow = edge[cur_edge[from]].cap;
}
} for(int from = s; from != t; from = edge[cur_edge[from]].v){ //修改增广路上的边的容量
int tmp = cur_edge[from];
edge[tmp].cap -= cur_flow;
edge[tmp^].cap += cur_flow;
}
max_flow += cur_flow;
u = neck;
} int i;
for(i = cur_edge[u]; i != -; i = edge[i].next)
if(edge[i].cap && d[u] == d[edge[i].v]+)
break; if(i != -){
cur_edge[u] = i;
pre[edge[i].v] = u;
u = edge[i].v;
}
else{
numd[d[u]]--;
if(!numd[d[u]]) break;
cur_edge[u] = head[u];
int tmp = n;
for(int j = head[u]; j != -; j = edge[j].next)
if(edge[j].cap && tmp > d[edge[j].v])
tmp = d[edge[j].v]; d[u] = tmp+;
numd[d[u]]++;
if(u != s)
u = pre[u];
}
}
return max_flow;
} inline void pre_init(){
cnt = ;
memset(head, -, sizeof head);
} void mapping(){
int u, v, w;
for(int i = ; i <= m; ++i){
scanf("%d %d %d", &u, &v, &w);
addedge(u, v, w);
addedge(v, u, w);
}
} int main(){ int tcase;
scanf("%d",&tcase);
while(tcase--){
scanf("%d%d",&n,&m);
int x,y,s,t;
int minn = inf, maxx = -inf;
for(int i = ; i <= n; i++){
scanf("%d%d",&x,&y);
if(x <= minn){
s = i;
minn = x;
}
if(x >= maxx){
t = i;
maxx = x;
}
}
pre_init();
mapping();
int ans = SAP(s,t);
printf("%d\n",ans);
}
return ;
}

【HDUOJ】4280 Island Transport的更多相关文章

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

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

  2. HDU 4280 Island Transport

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

  3. Hdu 4280 Island Transport(最大流)

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

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

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

  5. HDU 4280 Island Transport(网络流)

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

  6. 【LeetCode】463. Island Perimeter

    You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represen ...

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

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

  8. 【LeetCode】463. Island Perimeter 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 减去相交部分 参考资料 日期 题目地址:https: ...

  9. 【HDOJ】1385 Minimum Transport Cost

    Floyd.注意字典序!!! #include <stdio.h> #include <string.h> #define MAXNUM 55 #define INF 0x1f ...

随机推荐

  1. Sql Server 表结构相关

    1.库表列信息 --取所有库 SELECT Name FROM Master..SysDatabases ORDER BY Name --查询所有表 select name from 库名..syso ...

  2. CSS 中功能相似伪类间的区别

    导读: CSS3 中有许多伪类选择器,其中一些伪类选择器的作用近似却又不完全一样,下面我们就来看一看到底有什么不一样. 1.:only-child 与 :only-of-type 测试的代码: < ...

  3. linux终端命令行缩短显示路径

    1,修改.bashrc文件(用户根目录下) vim 打开.bashrc文件,找到如下这行: else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ...

  4. mySQL学习入门教程——2.创建表

    二.创建表 一.创建数据表的SQL语句模型(弱类型)CREATE TABLE [IF NOT EXISTS] 表名称(字段名1 列的类型[属性][索引],字段名2 列的类型[属性][索引],-字段名n ...

  5. 自定义DbUtils通用类

    本实例使用C3P0连接池做连接,详见https://www.cnblogs.com/qf123/p/10097662.html开源连接池C3P0的使用 DBUtils.java package com ...

  6. 如何取消IDEA的自动删除行尾空格?

    使用IDEA,添加注释的时候敲空格,总是会把行尾空格删除导致代码跑到注释行,很不爽~~ 取消这个不爽的功能:File--Settings--Editor--General--Other--Strip ...

  7. Android开发——回调(Callback)

    1. 回调函数的定义: 在A类中定义了一个方法,这个方法中用到了一个接口和该接口中的抽象方法,但是抽象方法没有具体的实现,需要B类去实现,B类实现该方法后,它本身不会去调用该方法,而是传递给A类,供A ...

  8. 【知识强化】第五章 输入/输出(I/O)管理 5.2 I/O核心子系统I

    学习I/O核心子系统相关的一系列功能. 设备独立性软件.设备驱动程序.中断处理程序这三层其实是属于操作系统的内核部分的,所以它们也称作“I/O核心子系统”,又可以简称为“I/O系统”.在考研当中我们需 ...

  9. http(python)

    1.client 1) httpie http -f POST example.org hello=World http POST http://192.168.200.251:55101/Api/C ...

  10. sort -n

    输入如下测试数据:  当按照第一列排列时是正确的:  但按照第二列排序时,喵喵喵???怎么跟说好的不一样啊!!!为什么gugu的50会排在最后?  其实是因为默认是按照第二列的第一个字符来比较的,若想 ...