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 最大流的更多相关文章

  1. HDU4280 Island Transport —— 最大流 ISAP算法

    题目链接:https://vjudge.net/problem/HDU-4280 Island Transport Time Limit: 20000/10000 MS (Java/Others)   ...

  2. 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 ...

  3. HDU4280 Island Transport

    ISAP求最大流模板 #include<cstdio> #include<cstring> #include<algorithm> #include<iost ...

  4. HDU4280:Island Transport(最大流)

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

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

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

  6. Hdu 4280 Island Transport(最大流)

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

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

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

  8. Island Transport

    Island Transport http://acm.hdu.edu.cn/showproblem.php?pid=4280 Time Limit: 20000/10000 MS (Java/Oth ...

  9. HDU 4280 Island Transport

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

随机推荐

  1. CF712E [Memort and Casinos]

    题意 每次询问一段区间[l,r],求从最左边走到最右边(r+1)的概率(若走到l-1,则GG了),每个点上写有向右走的概率.支持单点修改. 思考 若只查询一次,那只要知道每个点在不走到l-1的情况下, ...

  2. RabbitMQ 设置消息的优先级

    在RabbitMQ中,可以设置消息的优先级,也就相当于在队列中置顶某条消息,让某个消息优先得到处理的功能. 既然是设置消息的优先级,那么就是针对生产者,也就是消息发布端. 设置消息的优先级一共有2个步 ...

  3. memset详解 设置无穷大INF

    memest原型 (please type "man memset" in your shell) void *memset(void *s, int c, size_t n); ...

  4. ubuntu查看占用某端口的程序

    查看端口使用情况,使用netstat命令. 查看已经连接的服务端口(ESTABLISHED netstat -a 查看所有的服务端口(LISTEN,ESTABLISHED) netstat -ap 查 ...

  5. Edit Distance II

    Given two strings S and T, determine if they are both one edit distance apart. Example Given s = &qu ...

  6. Asp.Net WebApi核心对象解析(一)

    生活需要自己慢慢去体验和思考,对于知识也是如此.匆匆忙忙的生活,让人不知道自己一天到晚都在干些什么,似乎每天都在忙,但又好似不知道自己到底在忙些什么.不过也无所谓,只要我们知道最后想要什么就行.不管怎 ...

  7. Java语法基础学习DayTwo

    一.数据类型补充问题 数据类型的自动转换等级: byte,short,char -- int -- long -- float -- double long是8个字节,float是4个字节,为什么是这 ...

  8. Tap 模拟手势点击坐标

    前言:有时候元素怎么都定位不到,没办法就只能坐标定位了,不过这个坐标定位不准确,换个手机就可能定位不到了,这是一个下下策的定位方式. tap用法 1.tap是模拟手指点击页面上元素语法有两个参数,第一 ...

  9. Word2Vec实现原理(Hierarchical Softmax)

    由于word2vec有两种改进方法,一种是基于Hierarchical Softmax的,另一种是基于Negative Sampling的.本文关注于基于Hierarchical Softmax的改进 ...

  10. js 自执行匿名函数(转载)

    自执行匿名函数: 常见格式:(function() { /* code */ })(); 解释:包围函数(function(){})的第一对括号向脚本返回未命名的函数,随后一对空括号立即执行返回的未命 ...