题目链接: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. java多线程学习笔记(四)

    上一节讲到Synchronized关键字,synchronized上锁的区域:对象锁=方法锁/类锁 本节补充介绍一下synchronized锁重入: 关键字synchronized拥有锁重入的功能,也 ...

  2. FrameWork内核解析之布局加载与资源系统(三)

    阿里P7Android高级架构进阶视频免费学习请点击:https://space.bilibili.com/474380680本篇文章将继续从以下两个内容来介绍布局加载与资源系统: [ LayoutM ...

  3. linux Cron 定时任务(centos 7.2 测试可用)

    1.Cron(学习笔记) 计划任务,是任务在约定的时间执行已经计划好的工作. 格式如下 Seconds Minutes Hours DayofMonth Month DayofWeek Year    ...

  4. Linux部署web项目

    一.软件1.putty2.WinSCP 二.调试1.linux 下 apache启动.停止.重启命令基本的操作方法:本文假设你的apahce安装目录为/usr/local/apache2,这些方法适合 ...

  5. iView的表单table

    // html<div class="exam-list"> <Table :columns="columns7" :data="d ...

  6. 安装FTP

    yum install vsftpd -y cd /etc/vsftpd/ touch login.txt vim login.txt db_load -T -t hash -f /etc/vsftp ...

  7. jquery.cookie.js实现cookie记住用户名和密码

    记得导入 <script src="jquery.js" type="text/javascript"></script> <sc ...

  8. START TRANSACTION - 开始一个事务块

    SYNOPSIS START TRANSACTION [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ...

  9. springMVC+freemarker整合

    转自:http://angelbill3.iteye.com/blog/1980904 在springMVC的项目中,加入freemarker 1.首先导入springMVC-webmvc所需的JAR ...

  10. .babelrc配置例子

    { "presets":[ ["es2015",{"modlues":false}], "react", ], &quo ...