hdu4280 Island Transport 最大流
In the vast waters far far away, there are many islands. People are living on the islands, and all the transport among the islands relies on the ships.
You have a transportation company there. Some routes are opened for passengers. Each route is a straight line connecting two different islands, and it is bidirectional. Within an hour, a route can transport a certain number of passengers in one direction. For safety, no two routes are cross or overlap and no routes will pass an island except the departing island and the arriving island. Each island can be treated as a point on the XY plane coordinate system. X coordinate increase from west to east, and Y coordinate increase from south to north.
The transport capacity is important to you. Suppose many passengers depart from the westernmost island and would like to arrive at the easternmost island, the maximum number of passengers arrive at the latter within every hour is the transport capacity. Please calculate it.
题意:给出若干个点和点之间边的流量,问最西边的点到最东边的点的运量是多少
题意描述就是一个裸的网络流最大流问题,直接跑dinic就可以了
#pragma comment(linker,"/STACK:16777216")
#include<stdio.h>
#include<string.h>
const int maxm=;
const int maxv=;
const int INF=0x3f3f3f3f; int s,t;
int n,m;
int d[maxm],cur[maxm];
bool vis[maxm];
int head[maxm],point[maxv],flow[maxv],nxt[maxv],size; void init(){
size=;
memset(head,-,sizeof(head));
} void add(int a,int b,int c){
point[size]=b;
flow[size]=c;
nxt[size]=head[a];
head[a]=size++;
point[size]=a;
flow[size]=c;
nxt[size]=head[b];
head[b]=size++;
} bool bfs(){
memset(vis,,sizeof(vis));
int q[maxm],cnt=;
q[++cnt]=s;
vis[s]=;
d[s]=;
for(int i=;i<=cnt;i++){
int u=q[i];
for(int j=head[u];~j;j=nxt[j]){
if(!vis[point[j]]&&flow[j]>){
d[point[j]]=d[u]+;
q[++cnt]=point[j];
vis[point[j]]=;
}
}
}
return vis[t];
} int dfs(int x,int a){
if(x==t||a==)return a;
int ans=,f;
for(int i=head[x];~i;i=nxt[i]){
if(d[point[i]]==d[x]+&&flow[i]>){
f=dfs(point[i],a<flow[i]?a:flow[i]);
flow[i]-=f;
flow[i^]+=f;
ans+=f;
a-=f;
if(a==)break;
}
}
if(ans==)d[x]=-;
return ans;
} int mf(){
int ans=;
while(bfs()){
ans+=dfs(s,INF);
}
return ans;
} int main(){
int T;
scanf("%d",&T);
for(int q=;q<=T;q++){ init();
scanf("%d%d",&n,&m);
int i,j,minx,maxx;
for(i=;i<=n;i++){
int x,y;
scanf("%d%d",&x,&y);
if(i==){
minx=x;
maxx=x;
s=t=i;
}
else{
if(x>maxx){
maxx=x;
s=i;
}
else if(x<minx){
minx=x;
t=i;
}
}
}
for(i=;i<=m;i++){
int a,b,v;
scanf("%d%d%d",&a,&b,&v);
add(a,b,v);
}
printf("%d\n",mf());
}
return ;
}
hdu4280 Island Transport 最大流的更多相关文章
- HDU4280 Island Transport —— 最大流 ISAP算法
题目链接:https://vjudge.net/problem/HDU-4280 Island Transport Time Limit: 20000/10000 MS (Java/Others) ...
- Hdu4280 Island Transport 2017-02-15 17:10 44人阅读 评论(0) 收藏
Island Transport Problem Description In the vast waters far far away, there are many islands. People ...
- HDU4280 Island Transport
ISAP求最大流模板 #include<cstdio> #include<cstring> #include<algorithm> #include<iost ...
- HDU4280:Island Transport(最大流)
Island Transport Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 4280 Island Transport(网络流,最大流)
HDU 4280 Island Transport(网络流,最大流) Description In the vast waters far far away, there are many islan ...
- Hdu 4280 Island Transport(最大流)
Island Transport Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- HDU 4280 Island Transport(dinic+当前弧优化)
Island Transport Description In the vast waters far far away, there are many islands. People are liv ...
- Island Transport
Island Transport http://acm.hdu.edu.cn/showproblem.php?pid=4280 Time Limit: 20000/10000 MS (Java/Oth ...
- HDU 4280 Island Transport
Island Transport Time Limit: 10000ms Memory Limit: 65536KB This problem will be judged on HDU. Origi ...
随机推荐
- 0-MAVEN SETTING
localRepository : 表示本地库的保存位置,也就是maven主要的jar包保存位置,默认在${user.dir}/.m2/repository,如果需要另外设置,就换成其他的路径 Ser ...
- learning scala output to console
控制台输出语句: print println example: scala> print("i=");print(i)i=345scala> println(" ...
- js 小说格式整理
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...
- Oracle Rman 控制RMAN的备份时间,减少IO消耗
一.问题描述 由于服务器配置不高,备份策略为周末全备.周一至周六差异备份. 平时服务器CPU使用30%左右. 全备份时,开启两个通道,CPU达到70%-80%左右,业务不卡顿.不掉单,session不 ...
- MySQL/MariaDB 版本选择
ALPHA.BETA.Release Candidate(RC).Release.GA等版本号的意义 MySQL数据库会存在很多版本,在这么多的版本中,我们如何进行选择,那么,首先我们要了解各个版本号 ...
- day22 模块_1
核能来袭--模块 1.简单了解模块 2.Collections 3.Time模块 4.functools 一.初识模块 其实之前写的每一个PY文件都是一个模块 还有一些我们一直在使用的模块 buil ...
- redis、memcached、mongoDB 对比
Mongodb和Memcached不是一个范畴内的东西.Mongodb是文档型的非关系型数据库,其优势在于查询功能比较强大,能存储海量数据.Mongodb 和 Memcached不存在谁替换谁的问题. ...
- 深入理解java虚拟机---虚拟机工具jhat(十六)
jhat JVM Heap Analysis Tool命令是与jmap搭配使用,用来分析jmap生成的dump,jhat内置了一个微型的HTTP/HTML服务器,生成dump的分析结果后,可以在浏览器 ...
- Android开发---基本UI组件1:自动拨电话,自动上网,输入框不换行、只输数字、只输文本、只输密码
1.activity_main.xml 描述:构建一个按钮 <?xml version="1.0" encoding="utf-8"?> <L ...
- mybatis学习(一)----入门
一.Mybatis介绍 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名 ...