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 ...
随机推荐
- 二:通过VirtualBox+Vagrant创建一个centos的虚拟机:
官网安装VirtualBox及Vagrant. 下载centos7,添加到vagrant中. http://e-proxy.yfb.sunline.cn/download/vagrant/centos ...
- x多进程
#!/usr/bin/env python3 # -*- coding: utf-8 -*- ''' from multiprocessing import Process import os #子进 ...
- 学react的第一天
属性 class = className for = htmlFrom jsx语法被编译了,所以可以在return里写html标签 react的属性 constructor(props){ super ...
- Cracking The Coding Interview 1.1
//原文: // // Implement an algorithm to determine if a string has all unique characters. What if you c ...
- ROS tab键补全操作出现错误
ros tab键补全操作出现错误如下: $ roslaunch sp[rospack] Warning: error while crawling /home/hemudu: boost::files ...
- 201621123001 《Java程序设计》第6周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰 ...
- sptring boot 修改默认Banner
一.自定义banner 启动Spring Boot项目时,在控制台或日志中会默认显示一个Banner,如图所示: 在我们的项目中更希望使用自己的Banner,这样看起来更帅写,但是这对于程序员来说并不 ...
- python 列表和元组
一,基本的列表操作 1.该表列表,元素赋值 示例: >>>x = [1,1,1] >>>x[1] = 2 >>>x [1,2,1] 2.删除元素 ...
- Delphi 10.3.1来了
10.3.1发布了,这个版本可以独自安装,是对Delphi 10.3 Rio,C ++ Builder 10.3 Rio和RAD Studio 10.3 Rio的更新.如果安装了2018年11月发布的 ...
- JAVA之字母与相对应数字转换
26个字母大小写加起来就是52个.对应的数字范围 System.out.println((char)97);//aSystem.out.println((char)122);//zSystem.out ...