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 ...
随机推荐
- JAVA按数字,字母排序,但不包括大小写和汉字排序
public class ABC { public static void main(String[] args) { new ABC().sortStringArray(); } public vo ...
- [javamail]AUTH LOGIN failed;Invalid username or password报错
项目中需要用到javamailAPI,邮箱服务器用的sohu闪电邮,SMTP协议用来发送,赋值代码: Properties props = new Properties(); props.setPro ...
- day044 cssy其他样式 js初识
float: 浮动 .t1{ float: right/left; } 关于浮动的两个特点: 1.浮动的框可以向左或向右移动,知道他的外边缘碰到包括框或另一个浮动框的边框为止. 2.由于浮动框不在文档 ...
- flask-admin fileadmin 上传文件,中文名的解决方案 重写部分secure_filename
class upload_view(FileAdmin): def _save_form_files(self, directory, path, form): super() filename = ...
- 一个表中多个字段对应另一个表的ID(SQL查询)
A数据表中多个字段对应B数据表的ID, 现在要把B表的其他字段一起查询出来 一.数据表: 1.SPEED_DETECTION_ROAD 它的 START_POINT_ID 和 END_POINT_ID ...
- mysql 数据迁移
最近线上系统新挂了一次磁盘,需要将系统磁盘下的 mysql 数据目录迁移到 数据盘上. 经过一番考察,mysql在安装时,使用了预编译的二进制tar.gz包.共有两处配置了 datadir属性 /et ...
- Cracking The Coding Interview 9.1
//原文: // // You are given two sorted arrays, A and B, and A has a large enough buffer at the end to ...
- Linux文件管理常用命令用法总结
1.touch change file timestamps. 命令用于修改文件或者目录的时间属性,包括存取时间和更改时间.若文件不存在,系统会建立一个新的文件.stat,ls -l 可以显示档案的时 ...
- fabric运维
fabric中文文档:http://fabric-chs.readthedocs.io/zh_CN/chs/ 视频教程:http://study.163.com/course/courseMain.h ...
- 什么是RUP
Rational统一过程(Rational Unified Process,RUP)是由Rational软件公司推出的一种完整且完美的软件过程. RUP总结了经过多年商业化验证的6条最有效的软件开 ...